forked from jjfiv/CSC262P1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEcho.java
More file actions
49 lines (45 loc) · 1.01 KB
/
Copy pathEcho.java
File metadata and controls
49 lines (45 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package edu.smith.cs.csc262.coopsh.apps;
import edu.smith.cs.csc262.coopsh.ShellEnvironment;
import edu.smith.cs.csc262.coopsh.Task;
/**
* This is a full implementation of Echo.
* @author jfoley
*
*/
public class Echo extends Task {
/**
* Store the lines present in the user input.
*/
final String[] lines;
/**
* Store the current index into the list for printing.
*/
int i = 0;
/**
* Construct an Echo Task.
* @param env - the shell environment.
* @param args - the arguments to echo.
*/
public Echo(ShellEnvironment env, String[] args) {
super(env, args);
StringBuilder sb = new StringBuilder();
for(int i=0; i<args.length; i++) {
if (i > 0) sb.append(",");
sb.append(args[i]);
}
this.lines = sb.toString().split("\n");
}
/**
* Update is like the body of a loop.
*/
@Override
protected void update() {
if (i < this.lines.length) {
this.println(this.lines[i]);
i++;
} else {
this.closeOutput();
this.exit(0);
}
}
}