|
1 | 1 | In this stage, you'll implement support for appending the output of a command to a file. |
2 | 2 |
|
3 | | -The `1>>` operator is used to append the output of a command to a file. |
4 | | -As a special case, if the file descriptor is not specified before the operator `>>`, the output is redirected to the standard output by default, so `>>` is equivalent to `1>>`. |
| 3 | +### The `>>` Operator |
5 | 4 |
|
6 | | -Learn more about [Appending Stdout](https://www.gnu.org/software/bash/manual/bash.html#Appending-Redirected-Output). |
| 5 | +The `>>` operator appends the standard output of a command to a file. Unlike `>`, which overwrites the file, `>>` adds the output to the end of the file and preserves any existing content. |
| 6 | + |
| 7 | +If the file doesn't exist, it is created (just like `>`). If the file already exists, the new output is added to the end. |
| 8 | + |
| 9 | +For example: |
| 10 | +```bash |
| 11 | +$ echo first >> output.txt |
| 12 | +$ echo second >> output.txt |
| 13 | +$ cat output.txt |
| 14 | +first |
| 15 | +second |
| 16 | +``` |
| 17 | + |
| 18 | +You can also explicitly write `1>>` to append the command's standard output to a file. Both `>>` and `1>>` do exactly the same thing. |
7 | 19 |
|
8 | 20 | ### Tests |
9 | 21 |
|
10 | 22 | The tester will execute your program like this: |
11 | | - |
12 | 23 | ```bash |
13 | | -./your_program.sh |
| 24 | +$ ./your_program.sh |
14 | 25 | ``` |
15 | 26 |
|
16 | | -It'll then send a series of commands to your shell, executing commands and appending their output to a file: |
17 | | - |
| 27 | +It will then send a series of commands to your shell and attempt to append their output to a file: |
18 | 28 | ```bash |
19 | 29 | $ ls /tmp/baz >> /tmp/bar/bar.md |
20 | 30 | $ cat /tmp/bar/bar.md |
21 | 31 | apple |
22 | 32 | banana |
23 | 33 | blueberry |
| 34 | + |
24 | 35 | $ echo 'Hello Emily' 1>> /tmp/bar/baz.md |
25 | 36 | $ echo 'Hello Maria' 1>> /tmp/bar/baz.md |
26 | 37 | $ cat /tmp/bar/baz.md |
27 | 38 | Hello Emily |
28 | 39 | Hello Maria |
| 40 | + |
29 | 41 | $ echo "List of files: " > /tmp/bar/qux.md |
30 | 42 | $ ls /tmp/baz >> /tmp/bar/qux.md |
31 | 43 | $ cat /tmp/bar/qux.md |
|
35 | 47 | blueberry |
36 | 48 | ``` |
37 | 49 |
|
38 | | -The tester will check if the commands correctly execute commands and append their output to a file as specified. |
39 | | -The file contents will also be checked for correctness. |
| 50 | +The tester will verify that: |
| 51 | +- Commands with `>>` append their standard output to the specified file |
| 52 | +- Commands with `1>>` work identically to `>>`. |
| 53 | +- Existing file content is preserved (not overwritten). |
| 54 | +- Files are created if they don't exist. |
0 commit comments