In an earlier mission, we looked at how to redirect output from a command to a file using >
. Here's an example:
echo "This is all a dream..." > dream.txt
If the file dream.txt
already exists, the above code will overwrite the file with the string This is all a dream...
. If the file dream.txt
doesn't exist, it will be created, and the stringThis is all a dream...
will be used as the content. This involves redirecting from thestandard output of the command to the standard input of the file.
If we don't want to overwrite dream.txt
, and we instead want to add to it, we can use >>
.
echo "Wake up!" >> dream.txt
The above code will append This is all a dream...
to the file dream.txt
. The file will still be created if it didn't exist.
Instructions
- Overwrite the file
beer.txt
with the string99 bottles of beer on the wall...
. - Append the string
Take one down, pass it around, 98 bottles of beer on the wall...
to the filebeer.txt
~$ echo '99 bottles of beer on the wall...' > beer.txt ~$ echo 'Take one down, pass it around, 98 bottles of beer on the wall...' >> beer.txt