On Wed, Aug 18, 2010 at 12:36 PM, Marc Herbert <marc.herb...@gmail.com> wrote: > Compare: > > for a in "$(echo 1 2)"; do echo "x${a}x"; done > x1 2x > for a in $(echo 1 2) ; do echo "x${a}x"; done > x1x > x2x > > a="$(echo 1 2)"; echo "x${a}x" > x1 2x > a=$(echo 1 2); echo "x${a}x" > x1 2x > > > > Shell quoting is difficult enough; why is such an inconsistency making > it even more confusing? > > Uwe Waldmann might give a clue in his excellent "Guide to Unix shell > quoting": > > Note that in these [assignment + others] cases, the shell syntax > allows only a single word, not a sequence of words, so that blank > interpretation or expansion of globbing characters might result in > something syntactically illegal. > > In other words: > > In order to save you from some very obvious syntax errors, I'll > make quoting even more confusing than it already is. > > Sorry but I am not grateful at all. > > Or is there a better rationale for this design? >
What should a=* or a=$(echo 1 2) do? Assign only the first file or just 1 to a? or result in an error? This hardly seem more consistent or less surprising to me. There are other places where word splitting is disabled, in case, inside [[ ]]...etc...