Bash Scripting - Error HandlingWhich of the following is the correct way to print the exit code of the last command in bash?Aecho $?[]Becho $?()Cecho $?Decho $exitCheck Answer
Step-by-Step SolutionSolution:Step 1: Understand syntax for printing variablesIn bash, variables are printed using echo and the variable name with a $ sign, no parentheses or brackets.Step 2: Identify correct syntax for exit codeThe exit code is stored in $?, so printing it is done by echo $?.Final Answer:echo $? -> Option CQuick Check:Print exit code = echo $? [OK]Quick Trick: Print exit code with echo $? [OK]Common Mistakes:MISTAKESAdding parentheses or bracketsUsing wrong variable name
Master "Error Handling" in Bash Scripting9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Bash Scripting Quizzes Arrays - Why arrays handle lists of data - Quiz 7medium Arrays - Array slicing - Quiz 6medium Error Handling - Why error handling prevents silent failures - Quiz 1easy File Operations in Scripts - File existence checks - Quiz 13medium Functions - Function arguments ($1, $2 inside function) - Quiz 2easy Functions - Why functions organize reusable code - Quiz 3easy String Operations - String length (${#var}) - Quiz 11easy Text Processing in Scripts - grep in scripts - Quiz 1easy Text Processing in Scripts - Here strings (<<<) - Quiz 13medium Text Processing in Scripts - Why scripts often process text - Quiz 10hard