Bash Commands - $? for testing the result of a command

$? is especially useful for testing the result of a command in a script .

#!/bin/bash
echo hello                                
echo $?
             # Exit status 0 returned because command executed successfully.

lskdf                   # Unrecognized command.
echo $?             # Non-zero exit status returned because command failed to execute.


echo
exit 113
             # Will return 113 to shell.



# To verify this, type "echo $?" after script terminates.
# By convention, an 'exit 0' indicates success,
#+ while a non-zero exit value means an error or anomalous condition.




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章