0
0
Bash Scriptingscripting~10 mins

Why debugging saves hours in Bash Scripting - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to print a message showing the script started.

Bash Scripting
echo [1]
Drag options to blanks, or click blank then click option'
A"Script started"
BScript started
C'Script started'
DScript_started
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.
2fill in blank
medium

Complete 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'
Af
Be
Cd
Ds
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-f' checks only for regular files, not directories.
Using '-d' checks only for directories.
3fill in blank
hard

Fix 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'
A`date`
B"date"
C$(date)
Ddate
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.
4fill in blank
hard

Fill 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'
A"*"
Bf
Ce
D"?"
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-e' instead of '-f' includes directories.
Using '?' matches only single character filenames.
5fill in blank
hard

Fill 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'
Adebug_message
B"Debugging saves hours"
Dprint_debug
Attempts:
3 left
💡 Hint
Common Mistakes
Calling a different function name than defined.
Not quoting the message string.