bug-bash
[Top][All Lists]
Advanced

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

Re: documentation for ${!prefix*} is misleading


From: Andreas Schwab
Subject: Re: documentation for ${!prefix*} is misleading
Date: Tue, 10 Aug 2010 16:15:30 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux)

Greg Wooledge <wooledg@eeg.ccf.org> writes:

> The 4.1 man page says:
>
>       ${!prefix*}
>       ${!prefix@}
>            Names matching prefix.  Expands to the names of variables whose
>            names begin with prefix, separated by the first character of the
>            IFS special variable.  When @ is used and the expansion appears
>            within double quotes, each variable name expands to a separate
>            word.
>
> Actually, the IFS rule only applies when the "${!prefix*}" is quoted.

The IFS rules are the same as with $* and $@.

>   imadev:~$ IFS='+x'
>   imadev:~$ echo ${!P*}
>   P4CLIENT PAGER PATH PIPESTATUS PKG_CONFIG_PATH PPID PS1 PS2 PS4 PWD

${!P*} expands to P4CLIENT+PAGER+PATH+... and word splitting splits it
on any character in $IFS, which echo receives as separate arguments.

Try this to see the difference:

$ o=$IFS; IFS=+; a=${!P*}; IFS=$o; echo $a

>   imadev:~$ echo "${!P*}"
>   P4CLIENT+PAGER+PATH+PIPESTATUS+PKG_CONFIG_PATH+PPID+PS1+PS2+PS4+PWD

"${!P*}" expands to a single word, no word splitting is performed on it.

> I believe this is intended behavior (since it matches how $* works),
> and that the man page is simply misleading.

Parameter expansion and word splitting are two separate steps.  The
quote above only talks about the former.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



reply via email to

[Prev in Thread] Current Thread [Next in Thread]