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 argumentsThe 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.
  Found a mistake? Have a question or improvement idea?
  Let me know.
      
      Table Of Contents