我使用了$(())
命令,我看到了这个错误:
bash: 0: command not found
为什么会出现这个错误?
的$(( ))
是算术取代或算术扩展。在其中,您可以执行(整数)算术运算,shell 将执行它们并用这些运算的结果替换整个表达式。
你经常看到它像在
count=$(( count + 1 ))
由于这里 shell 无事可做(算术替换为空),您的bash
shell 决定结果为零。
您将其用作命令,这意味着 shell 会尝试将结果0
, 作为命令运行。
它失败,并告诉您原因(“0:未找到命令”)。
这是一个空的算术替换,似乎是在不同 shell 中被不同处理的极端情况。该bash
外壳,沿zsh
和pdksh
(ksh
在OpenBSD)试图执行0
,同时dash
和yash
抱怨:
$ dash -c '$(( ))'
dash: 1: arithmetic expression: expecting primary: " "
$ yash -c '$(( ))'
yash: arithmetic: a value is missing
该POSIX标准说
作为扩展,shell 可以识别超出列出的算术表达式。
...这可能是 what bash
,zsh
和pdksh
do (即,他们将空表达式识别为“零”)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句