Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if the first argument is the long option '--help'.
Bash Scripting
if [ "$1" = [1] ]; then echo "Help option selected" fi
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using single dash '-h' instead of double dash '--help'.
Forgetting to quote the option string.
✗ Incorrect
The long option for help is '--help', so the code checks if the first argument equals '--help'.
2fill in blank
mediumComplete the code to use a case statement to handle the '--version' option.
Bash Scripting
case "$1" in [1]) echo "Version 1.0" ;; esac
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-v' instead of '--version'.
Missing quotes around the option.
✗ Incorrect
The case statement matches the '--version' long option to print the version info.
3fill in blank
hardFix the error in the code to correctly parse the '--output' option with a value.
Bash Scripting
if [[ $1 == [1] ]]; then output_file=$2 fi
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using single dash '-o' instead of '--output'.
Using single brackets [ ] which do not support pattern matching.
✗ Incorrect
The long option '--output' is matched with $1 to assign the next argument as the output file.
4fill in blank
hardFill both blanks to correctly parse '--file' option and assign its value.
Bash Scripting
if [[ $1 == [1] ]]; then file_name=[2] fi
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning $1 instead of $2 as the file name.
Using single dash '-file' instead of '--file'.
✗ Incorrect
The code checks if $1 is '--file' and assigns the next argument $2 to file_name.
5fill in blank
hardFill all three blanks to create a case statement that handles '--help', '--version', and '--output' options.
Bash Scripting
case "$1" in [1]) echo "Show help" ;; [2]) echo "Show version" ;; [3]) echo "Output file: $2" ;; esac
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-o' instead of '--output'.
Mixing up option names or missing quotes.
✗ Incorrect
The case statement matches '--help', '--version', and '--output' options to their respective actions.