Recall & Review
beginner
What does the '>>' operator do in bash scripting?
The '>>' operator appends the output of a command to the end of a file without overwriting the existing content.
Click to reveal answer
beginner
How would you add the text 'Hello World' to the end of a file named 'greetings.txt'?
Use the command:
echo "Hello World" >> greetings.txt. This adds the text to the file without deleting existing content.Click to reveal answer
beginner
What happens if the file does not exist when you use '>>' to append?
If the file does not exist, bash creates a new file and then appends the output to it.
Click to reveal answer
beginner
Compare '>' and '>>' operators in bash.
'>' overwrites the file content with new output, while '>>' adds new output to the end of the file without removing existing content.
Click to reveal answer
beginner
Why is appending to files useful in scripting?
Appending lets you keep a log or add new data continuously without losing previous information, like saving multiple command outputs in one file.
Click to reveal answer
What does the command
echo "Test" >> file.txt do if file.txt exists?✗ Incorrect
The '>>' operator appends the text 'Test' to the end of the existing file.txt.
If file.txt does not exist, what happens when you run
echo "Hello" >> file.txt?✗ Incorrect
Bash creates file.txt and writes 'Hello' because '>>' creates the file if missing.
Which operator overwrites the content of a file?
✗ Incorrect
'>' overwrites the file content, replacing it with new output.
Why might you prefer '>>' over '>' in a script that logs events?
✗ Incorrect
'>>' appends new logs, preserving previous entries.
What command appends the output of
date to a file named log.txt?✗ Incorrect
'date >> log.txt' appends the current date and time to log.txt.
Explain how the '>>' operator works in bash scripting and give an example.
Think about adding text to a file without deleting what is already there.
You got /4 concepts.
Describe the difference between '>' and '>>' operators and when you would use each.
Consider what happens to the file content after running each operator.
You got /4 concepts.