Recall & Review
beginner
What does the special variable
$? represent in bash scripting?$? holds the exit code of the last command run. It tells if the command succeeded (0) or failed (non-zero).Click to reveal answer
beginner
What exit code usually means success in bash scripts?
An exit code of
0 means the command succeeded without errors.Click to reveal answer
beginner
How can you check the exit code of a command immediately after running it?
Right after running a command, type
echo $? to see its exit code.Click to reveal answer
intermediate
Why is it important to check exit codes in scripts?
Checking exit codes helps scripts know if a command worked or failed, so they can act accordingly.
Click to reveal answer
beginner
What does a non-zero exit code indicate?
A non-zero exit code means the command failed or had an error.
Click to reveal answer
What does
echo $? show in bash?✗ Incorrect
$? stores the exit code of the last command run.Which exit code means success?
✗ Incorrect
Exit code 0 means the command succeeded.
If a command fails, what is the usual exit code?
✗ Incorrect
Non-zero exit codes indicate failure or errors.
When should you check
$? in a script?✗ Incorrect
You check
$? immediately after a command to know its result.What is a common use of exit codes in scripts?
✗ Incorrect
Scripts use exit codes to decide what to do next.
Explain what
$? means and how you use it in a bash script.Think about how you know if a command worked or not.
You got /5 concepts.
Describe why checking exit codes is important when writing bash scripts.
Imagine your script needs to stop or try something else if a command fails.
You got /4 concepts.