$ a='I am a string with spaces'
$ [ $a = $a ] || echo "didn't match"
bash: [: too many arguments
didn't match
[ $a = $a ]
was interpreted as[ I am a string with spaces = I am a string with spaces ]
.[
is thetest
command for whichI am a string with spaces
is not a single argument, rather it's 6 arguments!!
$ [ $a = something ] || echo "didn't match"
bash: [: too many arguments
didn't match
[ $a = something ]
was interpreted as[ I am a string with spaces = something ]
$ [ $(grep . file) = 'something' ]
bash: [: too many arguments
The
grep
command returns a multiline string with spaces, so you can just imagine how many arguments are there...:D
See what, when and why for the basics.