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

来源:互联网 发布:java实现导出excel表 编辑:程序博客网 时间:2024/05/17 04:01

$? 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.




原创粉丝点击