Skip to content

Commit 033655d

Browse files
authored
Merge pull request #191 from codecrafters-io/TropicolX-patch-28
Revise "Append stdout #el9"
2 parents 03ea3ab + 426468c commit 033655d

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed
Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +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 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
54

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.
719

820
### Tests
921

1022
The tester will execute your program like this:
11-
1223
```bash
13-
./your_program.sh
24+
$ ./your_program.sh
1425
```
1526

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:
1828
```bash
1929
$ ls /tmp/baz >> /tmp/bar/bar.md
2030
$ cat /tmp/bar/bar.md
2131
apple
2232
banana
2333
blueberry
34+
2435
$ echo 'Hello Emily' 1>> /tmp/bar/baz.md
2536
$ echo 'Hello Maria' 1>> /tmp/bar/baz.md
2637
$ cat /tmp/bar/baz.md
2738
Hello Emily
2839
Hello Maria
40+
2941
$ echo "List of files: " > /tmp/bar/qux.md
3042
$ ls /tmp/baz >> /tmp/bar/qux.md
3143
$ cat /tmp/bar/qux.md
@@ -35,5 +47,8 @@ banana
3547
blueberry
3648
```
3749

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

Comments
 (0)