Recall & Review
beginner
What does the special variable
$0 represent in a bash script?$0 holds the name of the script or command being executed. It helps you know which script is running.Click to reveal answer
beginner
What information does
$1 provide in a bash script?$1 is the first argument passed to the script. If you run ./script.sh hello, then $1 is hello.Click to reveal answer
beginner
Explain the purpose of
$# in bash scripting.$# tells you how many arguments were passed to the script. It helps check if the user gave the right number of inputs.Click to reveal answer
intermediate
What does
$@ represent in a bash script?$@ is all the arguments passed to the script, treated as separate words. Useful to loop over all inputs.Click to reveal answer
intermediate
What is the use of
$? and $$ in bash?$? shows the exit status of the last command (0 means success). $$ is the process ID of the current shell, useful for unique temp files.Click to reveal answer
In a bash script, what does
$# represent?✗ Incorrect
$# counts how many arguments you gave to the script.Which special variable holds the exit status of the last command?
✗ Incorrect
$? tells if the last command worked (0) or failed (non-zero).If you want to access all arguments passed to a bash script as separate words, which variable do you use?
✗ Incorrect
$@ holds all arguments separately, perfect for loops.What does
$$ represent in a bash script?✗ Incorrect
$$ is the unique ID of the running script process.What value does
$0 hold inside a bash script?✗ Incorrect
$0 is the name of the script or command you ran.Describe the purpose of each special variable: $0, $1, $#, $@, $?, and $$ in bash scripting.
Think about what each variable tells you about the script or its inputs.
You got /6 concepts.
How would you use special variables to check if a user passed exactly two arguments to your bash script?
Counting arguments helps control script behavior.
You got /3 concepts.