Bad effects of word splitting

suggest change
$ 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 the test command for which I 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.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents