Bird
0
0

Which bash variable holds the exit code of the last executed command?

easy🧠 Conceptual Q2 of 15
Bash Scripting - Error Handling
Which bash variable holds the exit code of the last executed command?
A$#
B$!
C$$
D$?
Step-by-Step Solution
Solution:
  1. Step 1: Recall special bash variables

    Bash uses special variables for different purposes: $? for last exit code, $! for last background PID, $# for argument count, $$ for current PID.
  2. Step 2: Identify the exit code variable

    The variable $? stores the exit code of the last command executed.
  3. Final Answer:

    $? -> Option D
  4. Quick Check:

    Exit code variable = $? [OK]
Quick Trick: Use $? to check last command's success or failure [OK]
Common Mistakes:
MISTAKES
  • Using $! instead of $?
  • Confusing with $$ or $#

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes