Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to write the text 'Hello World' into a file named output.txt using echo.
Bash Scripting
echo "Hello World" [1] output.txt
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using >> appends instead of overwriting.
Using < which is for input redirection.
Using | which pipes output to another command.
✗ Incorrect
The > operator redirects the output of echo to a file, overwriting it if it exists.
2fill in blank
mediumComplete the code to append the text 'New Line' to the file log.txt using echo.
Bash Scripting
echo "New Line" [1] log.txt
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using > which overwrites the file.
Using < which is for input redirection.
Using | which pipes output to another command.
✗ Incorrect
The >> operator appends the output to the file without overwriting existing content.
3fill in blank
hardFix the error in the code to write formatted text with printf into file.txt.
Bash Scripting
printf "Name: %s\n" [1] > file.txt
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting the string, causing errors or unexpected output.
Using single quotes which may not expand variables if used.
Passing a bare word that is not defined.
✗ Incorrect
The argument to printf must be a string without quotes stripped by the shell, so use the string without quotes.
4fill in blank
hardFill both blanks to create a file with numbers 1 to 5, each on a new line, using printf and a loop.
Bash Scripting
for i in {1..5}; do printf "[1]\n" [2]; done > numbers.txt
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using i without $ which is treated as a string.
Using %s which is for strings, not numbers.
Not redirecting output to the file.
✗ Incorrect
Use %d as the format for integers and $i to pass the current loop value to printf.
5fill in blank
hardFill all three blanks to create a file with squares of numbers 1 to 3 using printf and arithmetic expansion.
Bash Scripting
for n in {1..3}; do printf "[1]: [2]\n" [3] $((n*n)); done > squares.txt
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same label twice.
Using incorrect variable names.
Not using arithmetic expansion correctly.
✗ Incorrect
Use 'Number' and 'Square' as labels, and 'n' as the variable for the number in the loop.