Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print a message showing the script started.
Bash Scripting
echo [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes causes multiple words to be treated as commands.
Using single quotes is okay but double quotes are preferred here.
✗ Incorrect
Use quotes to print the exact message with spaces.
2fill in blank
mediumComplete the code to check if a file named 'data.txt' exists.
Bash Scripting
if [[ -[1] data.txt ]]; then echo "File exists" fi
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-f' checks only for regular files, not directories.
Using '-d' checks only for directories.
✗ Incorrect
The '-e' flag checks if the file exists regardless of type.
3fill in blank
hardFix the error in the script to assign the output of 'date' command to a variable.
Bash Scripting
current_date=[1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning the command name as a string instead of its output.
Using quotes around the command name instead of substitution.
✗ Incorrect
Use $(command) to capture command output into a variable.
4fill in blank
hardFill both blanks to loop over files and print their names if they are regular files.
Bash Scripting
for file in [1]; do if [[ -[2] $file ]]; then echo "$file" fi done
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-e' instead of '-f' includes directories.
Using '?' matches only single character filenames.
✗ Incorrect
Use "*" to match all files and '-f' to check for regular files.
5fill in blank
hardFill all three blanks to create a function that prints 'Debugging saves hours' and call it.
Bash Scripting
function [1]() { echo [2] } [3]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Calling a different function name than defined.
Not quoting the message string.
✗ Incorrect
Define function 'debug_message', echo the message in quotes, then call 'debug_message'.