Why should there be a space after '[' and before ']' in Bash?
我试图编写一个使用
1 | if [$CHOICE -eq 1]; |
脚本给了我错误,直到我在
1 | if [ $CHOICE -eq 1 ]; |
我的问题是,为什么方括号周围的空间在bash中如此重要?
一旦你明白了
1 | help [ |
然而,尽管它们做的完全相同,但
1 | help test |
…了解更多信息。
此外,请注意,我有意使用的是
从另一个问题:
A bit of history: this is because '[' was historically not a shell-built-in but a separate executable that received the expresson as arguments and returned a result. If you didn't surround the '[' with space, the shell would be searching $PATH for a different filename (and not find it) . – Andrew Medico Jun 24 '09 at 1:13
1 | command arguments separated with space |