tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: bug in sh, probably, with test case

On 2012-12-20 14:52, David Laight wrote:
On Thu, Dec 20, 2012 at 02:22:52PM -0500, Greg Troxel wrote:

One of the git tests fails.  I have reduced the failure to a small test
p="--foo --bar"
func alt "alt ${p:+$p}"

Yes that should only generate one parameter.
The 'problem' is cause because the internal expansion of $p
isn't actually quoted, "$alt ${p:+"$p"}" is needed for that.
Not being quoted means it should be subject to things like filename
globbing.  (someone is going to tell me that is wrong!)(

That's almost correct. The POSIX spec says the inner word is only subject to tilde expansion, parameter expansion, command substitution, and arithmetic expansion. The expansion of the entire word is still subject to field splitting, pathname expansion, and quote removal. Thus:

"a${PWD+*}" expands to the string a* (even if there are files beginning with 'a' in the directory)

"a${PWD+"*"}" also expands to the string a*, but interestingly it was the string "a"*"" before the quote removal step (none of those double quotes are themselves quoted according to the quoting rules, so they are all eliminated during the quote removal step)

a${PWD+*} expands to the list of files beginning with 'a' (one field per file) or the string a* if no such files exist

  a${PWD+"*"} expands to the string a*

*${PWD+"*"} expands to the list of files ending with the character * (one field per file) or the string ** if no such files exist

IIRC the only quoted expansion that can generate multiple parameters
is "$@".



Home | Main Index | Thread Index | Old Index