Re: Parameter expansion fails when assigning a local variable

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

On Sun, Jun 28, 2009 at 11:39:16PM +0200, Cristian Ionescu-Idbohrn wrote:
> But wait a second.  Shouldn't quotes '"' around $@ protect the whole $@?
> It does so in different other context.  Why not here?

The whole point of $@ is to retain field splitting within double

2.5.2      Special Parameters
	   Listed below are the special parameters and the values to
	   which they shall expand. Only the values of the special
	   parameters are listed; see Section 2.6 (on page 2238) for
	   a detailed summary
	   of all the stages involved in expanding words.
	   @    Expands to the positional parameters, starting from
		one. When the expansion occurs within double-quotes,
		and where field splitting (see Section 2.6.5 (on
		page 2244)) is performed, each positional parameter
		shall expand as a separate field, with the provision
		that the expansion of the first parameter shall
		still be joined with the beginning part of the
		original word (assuming that the expanded parameter
		was embedded within a word), and the expansion of
		the last parameter shall still be joined with the
		last part of the original word. If there are no
		positional parameters, the expansion of '@' shall
		generate zero fields, even when '@' is double-quoted.

> There's som parallel unnatural behaviour I noticed:
> 	local var=$(some forked thing here)
> $(...)
> ^^   ^ doesn't seem to protect the resulting string. There seems to be a
> difference between:
> 	local h=$(grep --help)
> and:
> 	local h="$(grep --help)"
> Can anything motivate that?  Is that POSIX too?

As I said local is identical to any other utility in this respect,
including shell functions.

Visit Openswan at
Email: Herbert Xu ~{PmV>HI~} <herbert@xxxxxxxxxxxxxxxxxxx>
Home Page:
PGP Key:
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at

[LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

Powered by Linux