bash是否有赋值的返回码?
对于作业是否会发生变化,我有点困惑。bash是否有赋值的返回码?,bash,return-value,Bash,Return Value,对于作业是否会发生变化,我有点困惑。$? 到目前为止,我所尝试的: $ curl --fail http://ftp.redhat.com/redhat/brms/6.2.0/en/source/MD5 curl: (22) The requested URL returned error: 404 $ #I have verified that $? should be 22 at this point $ var=romeo # Does this change $? $ echo $? #
$?
到目前为止,我所尝试的:
$ curl --fail http://ftp.redhat.com/redhat/brms/6.2.0/en/source/MD5
curl: (22) The requested URL returned error: 404
$ #I have verified that $? should be 22 at this point
$ var=romeo # Does this change $?
$ echo $? # I expected this to return 22 , but I got zero below
0
请说明这一点。:) 来自
曼巴什
:
? Expands to the exit status of the most recently executed fore‐
ground pipeline.
所以作业改变了它。你做的任何事都会改变它
$ ls alsdaskkad
ls: cannot access alsdaskkad: No such file or directory
$ echo $?
2
$ echo $?
0
$ echo 1
1
$ echo $?
0
等等
正如上面所说:
即使回音也会改变回音
另一方面,
(退出XX)
是将$?
设置为任意值的有效方法。即使回显返回值也会更改返回值@123:paren打开一个子shell。@fedorqui:谢谢并感谢timeNote,“最近执行的前台管道”可以包括在赋值右侧执行的最后一个命令替换,因此foo=“$(echo bar;exit 10)$(echo baz;exit 3)”
将$?
设置为3。赋值语句本身没有退出状态,但如果没有其他语句设置它,则可以清除$?
的值。除了作为一个特例,我真的不知道如何解释它。