單詞分裂的不良影響

$ 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

瞭解基礎知識的內容,時間和原因