On Monday 04 October 2010 06:56, Rob Landley wrote:
> > a=''
> > for v in "$@""$a"; do echo "v=$v"; done  # doesn't print anything?!
> > for v in "$@""`echo`"; do echo "v=$v"; done  # doesn't print anything?!
> >
> > In my opinion, these should print nothing:
> 
> Um, the does that a= line at the top have one quote, or two?

Those are two single quotes. I set a to empty value.

> Essentially, the argument gets crushed down to "$@" before anything else 
> happens,

Which is wrong. Quote removal should happen much later than that:

http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html

-start quote-
The order of word expansion shall be as follows:

1. Tilde expansion (see Tilde Expansion),
   parameter expansion (see Parameter Expansion),
   command substitution (see Command Substitution),
   and arithmetic expansion (see Arithmetic Expansion)
   shall be performed, beginning to end. See item 5 in Token Recognition.
2. Field splitting (see Field Splitting) shall be performed on the portions of 
the fields generated by step 1, unless IFS is null.
3. Pathname expansion (see Pathname Expansion) shall be performed, unless set 
-f is in effect.
4. Quote removal (see Quote Removal) shall always be performed last.
-end quote-

Thus, "$@""" should be processed as follows:

"$@" -> (nothing) should happen in step 1, since it's parameter expansion.
"" is not changed at step 1.
End result of step 1 is: (nothing)""

Step 4: (nothing)"" -> (nothing)(null word) -> (null word)

Therefore, "$@""" should be treated as null word, not as nothing.

I tested dash and ksh, both agree with me.

-- 
vda
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to