Bird
0
0

Which of the following is the correct way to check the exit code of the last command in bash?

easy📝 Syntax Q12 of 15
Bash Scripting - Error Handling
Which of the following is the correct way to check the exit code of the last command in bash?
Aecho $exit_code
Becho $?
Cecho $lastcode
Decho $status
Step-by-Step Solution
Solution:
  1. Step 1: Recall special variable for exit code

    The special variable $? holds the exit code of the last command.
  2. Step 2: Verify correct syntax

    Using echo $? prints the exit code correctly.
  3. Final Answer:

    echo $? -> Option B
  4. Quick Check:

    Use $? to get last exit code [OK]
Quick Trick: Use $? immediately after command to get exit code [OK]
Common Mistakes:
MISTAKES
  • Using undefined variables like $exit_code
  • Forgetting to check $? right after command
  • Using $status which is not standard

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes