linux shell中如何接收程序返回值
1个回答
展开全部
$?
$?就是表示上一次脚本或者命令退出时的返回值。通常,0代表成功;非0代表出现错误。
类似的一些符号如$0 $1 $2 $@ $# 。
Before we move on, there is a perversity about tests in Bash shells that I want to discuss. It turns out, because of a historical accident that now might as well be cast in concrete, when a test is conducted or a command returns a result value, the numerical value for "true" is 0, and "false" is 1. Those of you who have some programming experience will likely find this reversal of intuition as annoying as I do.
Here is a way to get the result of the most recent logical test (and to show the weird reversal described above):
$ test -e .
$ echo $?
0
$ test -e xyz
$ echo $?
1
$?就是表示上一次脚本或者命令退出时的返回值。通常,0代表成功;非0代表出现错误。
类似的一些符号如$0 $1 $2 $@ $# 。
Before we move on, there is a perversity about tests in Bash shells that I want to discuss. It turns out, because of a historical accident that now might as well be cast in concrete, when a test is conducted or a command returns a result value, the numerical value for "true" is 0, and "false" is 1. Those of you who have some programming experience will likely find this reversal of intuition as annoying as I do.
Here is a way to get the result of the most recent logical test (and to show the weird reversal described above):
$ test -e .
$ echo $?
0
$ test -e xyz
$ echo $?
1
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询