0
0
Bash Scriptingscripting~10 mins

Command-line arguments ($1, $2, ...) in Bash Scripting - Interactive Code Practice

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

Complete 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'
A$1
B$2
C$0
D$#
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.
2fill in blank
medium

Complete 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'
A$0
B$2
C$1
D$#
Attempts:
3 left
💡 Hint
Common Mistakes
Using $1 instead of $2 for the second argument.
Using $0 which is the script name.
3fill in blank
hard

Fix 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'
A$1
B$*
C$0
D$#
Attempts:
3 left
💡 Hint
Common Mistakes
Using $1 which is the first argument, not the count.
Using $0 which is the script name.
4fill in blank
hard

Fill 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'
A$1
B$2
C$3
D$#
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up $2 and $3 for third argument.
Using $# which is argument count, not argument value.
5fill in blank
hard

Fill 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'
A$1
B$#
C$0
D$2
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.