linux shell中如何接收程序返回值

 我来答
sky28_sky28
2014-03-05 · TA获得超过404个赞
知道小有建树答主
回答量:299
采纳率:0%
帮助的人:242万
展开全部
$?
$?就是表示上一次脚本或者命令退出时的返回值。通常,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
本回答被提问者和网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式