Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print the first command-line argument.
Bash Scripting
echo "First argument is: $[1]"
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using $0 instead of $1 to get the first argument.
Using $# which gives the number of arguments, not the argument itself.
✗ Incorrect
The first command-line argument is accessed using $1 in bash scripts.
2fill in blank
mediumComplete the code to print the second command-line argument.
Bash Scripting
echo "Second argument is: $[1]"
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using $1 instead of $2 for the second argument.
Using $0 which is the script name.
✗ Incorrect
The second command-line argument is accessed using $2 in bash scripts.
3fill in blank
hardFix the error in the code to print all arguments count.
Bash Scripting
echo "Number of arguments: $[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 count.
Using $0 which is the script name.
✗ Incorrect
The special variable $# holds the number of command-line arguments.
4fill in blank
hardFill both blanks to print the first and third arguments.
Bash Scripting
echo "First: $[1], Third: $[2]"
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up $2 and $3 for third argument.
Using $# which is argument count, not argument value.
✗ Incorrect
Use $1 for the first argument and $3 for the third argument.
5fill in blank
hardFill all three blanks to print the script name, first argument, and total arguments count.
Bash Scripting
echo "Script: $[1], Arg1: $[2], Count: $[3]"
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using $1 for script name instead of $0.
Using $2 instead of $1 for first argument.
Using $1 or $2 instead of $# for count.
✗ Incorrect
Use $0 for script name, $1 for first argument, and $# for total arguments count.