gpt4 book ai didi

bash - bash 是否有分配的返回码?

转载 作者:行者123 更新时间:2023-11-29 09:46:41 24 4
gpt4 key购买 nike

我对赋值是否改变 $?

有点困惑

到目前为止我尝试了什么:

$ 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

请阐明这一点。 :)

最佳答案

来自 man bash:

   ?      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

等等。

作为123说:

Even echoing the return changes the return!

关于bash - bash 是否有分配的返回码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37046201/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com