Recall & Review
beginner
What does
$1 represent in a bash script?$1 is the first command-line argument passed to the script when you run it.Click to reveal answer
beginner
How do you access the second command-line argument in a bash script?
You use
$2 to get the second argument passed to the script.Click to reveal answer
beginner
What does
$# mean in a bash script?$# gives the number of command-line arguments passed to the script.Click to reveal answer
intermediate
How can you access all command-line arguments as a single string?
Use
$* to get all arguments as one string separated by spaces.Click to reveal answer
intermediate
What is the difference between
$* and $@ in bash?$* treats all arguments as a single word, while $@ treats each argument as a separate word, especially when quoted.Click to reveal answer
In a bash script, what does
$3 represent?✗ Incorrect
$3 is the third argument passed to the script.Which variable holds the number of command-line arguments in a bash script?
✗ Incorrect
$# gives the count of arguments passed.How do you access the script's own name inside a bash script?
✗ Incorrect
$0 holds the script's filename.What is the output of
echo "$*" if the script is run with arguments: apple banana cherry?✗ Incorrect
$* joins all arguments separated by spaces.Which is true about
"$@" in bash?✗ Incorrect
"$@" expands each argument as a separate quoted string.Explain how to use command-line arguments in a bash script and how to access the first three arguments.
Think about how you run a script with extra words after the script name.
You got /5 concepts.
Describe the difference between $* and $@ in bash scripting when handling multiple arguments.
Consider how quoting affects the way arguments are grouped.
You got /5 concepts.