首页 > 科技 > exit and echo $?

exit and echo $?

2006年5月13日 11点17分 发表评论 阅读评论

exit is very useful to debug the program, its syntax is : # exit n, Here n is a number between 0-255, if it is bigger than 255, for example, 256, the value retuned by issuing”echo $? ” will be evaluted in the following equation: n-255-1
That says, when n is 266, the returned result is 256-255-1 = 0 which is also the value of “$?”

eg:

# !/bin/bash
# ifexit
echo “Please input a number: ”
# input the testing number
read NUMB
# if statement
if [ “$NUMB” -eq “1” ]
then
echo “$NUMB = 1”
elif [ “$NUMB” -eq “2” ]
then
exit 222
else
exit 278
fi

Input | Output
—————————–
2 222
3 278-256=22

分类: 科技 标签:
  1. 本文目前尚无任何评论.
  1. 本文目前尚无任何 trackbacks 和 pingbacks.
您必须在 登录 后才能发布评论.