0
0
Bash Scriptingscripting~20 mins

Appending to files (>>) in Bash Scripting - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
File Append Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1:30remaining
What is the content of the file after appending?
You have a file named log.txt containing:
Line1

What will be the content of log.txt after running this command?
echo "Line2" >> log.txt
ALine1\n\nLine2
BLine2
CLine1\nLine2
DLine1
Attempts:
2 left
💡 Hint
Appending adds new content after existing content without removing it.
💻 Command Output
intermediate
1:30remaining
What happens when appending with a missing file?
If notes.txt does not exist, what will be the content of notes.txt after running?
echo "Start" >> notes.txt
ANothing happens, file remains missing
BError: notes.txt not found
CFile created but empty
DFile created with content: Start
Attempts:
2 left
💡 Hint
Appending creates the file if it does not exist.
📝 Syntax
advanced
2:00remaining
Which command correctly appends multiple lines to a file?
You want to append these two lines to data.txt:
First line
Second line

Which command will do this correctly?
Aecho "First line" >> data.txt && echo "Second line" >> data.txt
Becho "First line\nSecond line" >> data.txt
Cecho -e "First line\nSecond line" >> data.txt
Decho "First line" > data.txt && echo "Second line" >> data.txt
Attempts:
2 left
💡 Hint
Appending multiple lines can be done by multiple echo commands with >>.
🔧 Debug
advanced
2:00remaining
Why does this append command overwrite the file instead of appending?
A user runs:
echo "New entry" > file.txt >> file.txt

What is the problem with this command?
AThe command syntax is invalid and causes an error
BThe > operator runs first and overwrites the file before >> appends
CThe >> operator overwrites the file, not appends
DThe echo command ignores redirection operators
Attempts:
2 left
💡 Hint
Order of redirection operators matters in bash.
🚀 Application
expert
2:30remaining
How to append output of a command to a file safely in a script?
You want to append the output of date command to timestamps.log inside a bash script. Which line is the best to do this safely and avoid overwriting?
Adate >> timestamps.log
Becho $(date) >> timestamps.log && > timestamps.log
Cecho $(date) > timestamps.log
Ddate > timestamps.log
Attempts:
2 left
💡 Hint
Appending means adding without removing existing content.