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 thetestcommand, andI am a string with spacesis 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
grepcommand returns a multiline string with spaces, so[receives far more than three arguments.
See what, when and why for the basics.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents