单词分裂的不良影响

$ a='I am a string with spaces'
$ [ $a = $a ] || echo "didn't match"
bash: [: too many arguments
didn't match

[ $a = $a ] 被解释为 [ I am a string with spaces = I am a string with spaces ][test 命令,I am a string with spaces 不是单个参数,而是 6 个参数!

$ [ $a = something ] || echo "didn't match"
bash: [: too many arguments
didn't match

[ $a = something ] 被解释为 [ I am a string with spaces = something ]

$ [ $(grep . file) = 'something' ]
bash: [: too many arguments

grep 命令返回带有空格的多行字符串,因此你可以想象有多少个参数……:D

了解基础知识的内容,时间和原因