Bird
0
0

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

easy📝 Syntax Q3 of 15
Bash Scripting - Error Handling
Which of the following is the correct way to print the exit code of the last command in bash?
Aecho $?[]
Becho $?()
Cecho $?
Decho $exit
Step-by-Step Solution
Solution:
  1. Step 1: Understand syntax for printing variables

    In bash, variables are printed using echo and the variable name with a $ sign, no parentheses or brackets.
  2. Step 2: Identify correct syntax for exit code

    The exit code is stored in $?, so printing it is done by echo $?.
  3. Final Answer:

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

    Print exit code = echo $? [OK]
Quick Trick: Print exit code with echo $? [OK]
Common Mistakes:
MISTAKES
  • Adding parentheses or brackets
  • Using wrong variable name

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes