Skip to content

Commit 6f54d0a

Browse files
authored
Update documentation for '>>' operator usage
Clarify the usage of the '>>' operator for appending output to files, including examples and test expectations.
1 parent bfc0ef7 commit 6f54d0a

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed
Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,43 @@
11
In this stage, you'll implement support for appending the output of a command to a file.
22

3-
### The `1>>` Operator
3+
### The `>>` Operator
44

5-
The `1>>` operator is used to append the output of a command to a file.
6-
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>>`.
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.
76

8-
Learn more about [Appending Stdout](https://www.gnu.org/software/bash/manual/bash.html#Appending-Redirected-Output).
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 to standard output. Both `>>` and `1>>` do exactly the same thing.
919

1020
### Tests
1121

1222
The tester will execute your program like this:
13-
1423
```bash
15-
./your_program.sh
24+
$ ./your_program.sh
1625
```
1726

18-
It will then send a series of commands to your shell, executing commands, and appending their output to a file:
19-
27+
It will then send a series of commands to your shell and attempt to append their output to a file:
2028
```bash
2129
$ ls /tmp/baz >> /tmp/bar/bar.md
2230
$ cat /tmp/bar/bar.md
2331
apple
2432
banana
2533
blueberry
34+
2635
$ echo 'Hello Emily' 1>> /tmp/bar/baz.md
2736
$ echo 'Hello Maria' 1>> /tmp/bar/baz.md
2837
$ cat /tmp/bar/baz.md
2938
Hello Emily
3039
Hello Maria
40+
3141
$ echo "List of files: " > /tmp/bar/qux.md
3242
$ ls /tmp/baz >> /tmp/bar/qux.md
3343
$ cat /tmp/bar/qux.md
@@ -37,5 +47,8 @@ banana
3747
blueberry
3848
```
3949

40-
The tester will check if the commands are executed correctly and append their output to a file as specified.
41-
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

Comments
 (0)