Bird
0
0

Which of the following is the correct syntax to print the exit status of the last command in a bash script?

easy📝 Syntax Q3 of 15
Bash Scripting - Variables
Which of the following is the correct syntax to print the exit status of the last command in a bash script?
Aecho $#
Becho $0
Cecho $$
Decho $?
Step-by-Step Solution
Solution:
  1. Step 1: Recall the special variable for exit status

    $? holds the exit status of the last executed command.
  2. Step 2: Confirm the correct echo syntax

    Using echo $? prints that exit status correctly.
  3. Final Answer:

    echo $? prints last command's exit status -> Option D
  4. Quick Check:

    $? = Last command exit status [OK]
Quick Trick: Use $? to check last command success or failure [OK]
Common Mistakes:
MISTAKES
  • Using $0 or $$ instead of $?
  • Forgetting to echo the variable
  • Confusing $# with exit status

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes