首页 > 应用开发 > Java > bash scripts(2)
Example 3-1. exit / exit status
#!/bin/bash echo hello echo $? # Exit status 0 returned because command successful. lskdf # Unrecognized command. echo $? # Non-zero exit status returned. 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. |
Example 3-2. Negating a condition using !true # the "true" builtin.
echo "exit status of "true" = $?" # 0
! true
echo "exit status of "! true" = $?" # 1
# Note that the "!" needs a space.
# !true leads to a "command not found" error
# Thanks, S.C.
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/8503278/viewspace-890156/ ,如需转载,请注明出处,否则将追究法律责任。