Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print the name of the script being run.
Bash Scripting
echo "Script name is: [1]"
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using $1 which is the first argument, not the script name.
Using $$ which is the process ID, not the script name.
✗ Incorrect
The special variable $0 holds the name of the script being executed.
2fill in blank
mediumComplete the code to print the number of arguments passed to the script.
Bash Scripting
echo "Number of arguments: [1]"
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using $@ which lists all arguments, not the count.
Using $? which shows the last command's exit status.
✗ Incorrect
The special variable $# holds the count of arguments passed to the script.
3fill in blank
hardFix the error in the code to print all arguments as separate words.
Bash Scripting
echo [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using $# which gives only the number of arguments.
Using $0 which is the script name.
✗ Incorrect
The special variable $@ expands to all arguments as separate words.
4fill in blank
hardFill both blanks to check if the last command succeeded and print its exit code.
Bash Scripting
if [ [1] -eq 0 ]; then echo "Success with exit code [2]" fi
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using $$ which is the process ID, not exit status.
Using $# which counts arguments, not exit status.
✗ Incorrect
The special variable $? holds the exit status of the last command.
5fill in blank
hardFill all three blanks to print the script name, process ID, and all arguments.
Bash Scripting
echo "Script: [1]" echo "PID: [2]" echo "Args: [3]"
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up $@ and $# for arguments.
Using $? instead of $$ for process ID.
✗ Incorrect
Use $0 for script name, $$ for process ID, and $@ for all arguments.