ITPub博客

首页 > 应用开发 > Java > bash scripts(2)

bash scripts(2)

原创 Java 作者:VampireAlchemis 时间:2007-01-13 15:05:42 0 删除 编辑

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.

[@more@]

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/8503278/viewspace-890156/,如需转载,请注明出处,否则将追究法律责任。

上一篇: bash scripts(1)
下一篇: bash scripts(4)
请登录后发表评论 登录
全部评论
  • 博文量
    32
  • 访问量
    236184