Challenge - 5 Problems
File Writer Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
What is the content of the file after running this script?
Consider the following bash script that writes to a file named
output.txt. What will be the content of output.txt after running it?Bash Scripting
echo "Hello World" > output.txt printf "Line1\nLine2\n" >> output.txt
Attempts:
2 left
💡 Hint
Remember that > overwrites the file and >> appends to it.
✗ Incorrect
The first command writes "Hello World" and overwrites any existing content. The second command appends two lines: "Line1" and "Line2". So the file contains three lines in total.
💻 Command Output
intermediate2:00remaining
What does this command write to the file?
What will be the exact content of
data.txt after running this command?Bash Scripting
printf "%s\n" "apple" "banana" "cherry" > data.txt
Attempts:
2 left
💡 Hint
Each %s\n prints the string followed by a newline.
✗ Incorrect
The printf command prints each string followed by a newline, so the file ends with a newline after "cherry".
📝 Syntax
advanced2:00remaining
Which option correctly appends a line with a variable to a file?
You want to append the text "User: alice" to a file named
log.txt, where the username is stored in a variable user. Which command is correct?Bash Scripting
user=alice
Attempts:
2 left
💡 Hint
Think about how single and double quotes handle variables.
✗ Incorrect
Double quotes allow variable expansion, so $user becomes 'alice'. Single quotes do not expand variables, so $user is written literally. Also, >> appends, > overwrites.
🔧 Debug
advanced2:00remaining
Why does this script not write the expected content to the file?
This script is intended to write "Count: 5" to
count.txt. Why does it fail?Bash Scripting
count=5 echo 'Count: $count' > count.txt
Attempts:
2 left
💡 Hint
Check how quotes affect variables inside echo.
✗ Incorrect
Single quotes prevent the shell from expanding variables, so the literal string 'Count: $count' is written instead of 'Count: 5'.
🚀 Application
expert3:00remaining
How to write a multi-line formatted report to a file using printf?
You want to create a report file
Which command correctly writes this using a single printf command?
report.txt with the following content exactly (including newlines):Report Summary: - Total: 10 - Passed: 8 - Failed: 2 End of Report
Which command correctly writes this using a single printf command?
Attempts:
2 left
💡 Hint
Use printf format specifiers and escape sequences carefully.
✗ Incorrect
Option C uses printf with format specifiers %d and newline escapes \n correctly, writing the exact formatted report with variables.