Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
bash是否有赋值的返回码?_Bash_Return Value - Fatal编程技术网

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。赋值语句本身没有退出状态,但如果没有其他语句设置它,则可以清除
$?
的值。除了作为一个特例,我真的不知道如何解释它。