Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.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
为什么let--n的退出代码与bash中的let--n不同?_Bash_Shell - Fatal编程技术网

为什么let--n的退出代码与bash中的let--n不同?

为什么let--n的退出代码与bash中的let--n不同?,bash,shell,Bash,Shell,为什么它们的退出代码为1 n=1 let --n 为什么退出代码为0 n=1 let n-- 这也有退出代码1。。。为什么? n=1 let "n = n - 1" 曼巴什说: let arg [arg ...] Each arg is an arithmetic expression to be evaluated (see ARITH‐ METIC EVALUATION above). If the last arg evaluates t

为什么它们的退出代码为1

n=1
let --n
为什么退出代码为0

n=1 
let n--
这也有退出代码1。。。为什么?

n=1
let "n = n - 1"
曼巴什说:

let arg [arg ...]
          Each arg is an arithmetic expression to be evaluated (see ARITH‐
          METIC EVALUATION above).  If the last arg evaluates  to  0,  let
          returns 1; 0 is returned otherwise.

1-1=0,因此退出代码为1。

-n
之间的区别在于,第一项的值为
n-1
(先递减,然后求值),而第二项的值为
n
(后递减)。取值后,n总是少一个,但
--
的位置表示何时应将值复制到结果中。

只是好奇,为什么这个问题会投反对票?