Exit Status in Shell
Level 385 keystrokes
Exit status indicates success (0) or failure (non-zero) of commands.
Shell code
# -q prints nothing; if tests grep's exit status: 0 (a match) means true# If log.txt is missing, grep returns 2 and the else branch runs too1if grep -q "error" log.txt; then2 echo "Errors found!" # Ends the script with status 1 to signal failure to the caller3 exit 14else # Runs when no line contains error; prints: All clear5 echo "All clear"6fiOutput
All clear
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this Shell code and how often they appear.
"× 6-× 1;× 1!× 1.× 1