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, and I am a string with spaces is not a single argument; it is six 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 [ receives far more than three arguments.

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