help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] inconsistency in expansions


From: Chet Ramey
Subject: Re: [Help-bash] inconsistency in expansions
Date: Mon, 07 May 2012 09:28:47 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:11.0) Gecko/20120327 Thunderbird/11.0.1

On 5/7/12 9:09 AM, Bill Gradwohl wrote:
> On Sun, May 6, 2012 at 6:07 PM, Dan Douglas <address@hidden
> <mailto:address@hidden>> wrote:
> 
>     __
>     ${$x} isn't a valid expansion, so it throws an error, the pattern isn't
>     matched, and nothing happens. 
> 
> 
> I see it produces an error, but I still don't see why. If $x expands to 3
> why don't I get ${3} and then the expansion of ${3}? Why is it illegal?
> What bash rule makes it so?
> 
>     ${$#} expands to the shell's PID, and tries to chop off a pattern
>     matching the empty string at the beginning, which doesn't match the
>     pattern at the end of "$*", so nothing happens. "$3" expands to
>     "canary", which does match the pattern, so the string is modified.
> 
>  
> Here you lost me all together. $$ is the shell PID. How do you see this as
> having to do with a PID? You're probably right, but I don't see by what
> logic you arrive at that conclusion.

Dan and Pierre Gaston each gave a pretty good step-by-step explanation.
Keep in mind that $$ and ${$} are equivalent.

> Aren't expansions done from the inside out? 

No, they're not.  Maybe that's where your confusion stems from.  There are
places where expansion is performed, and places where it is not.  Greg
quoted the right place in the manual: the parameter between the braces in
${parameter[op[WORD]]} is not subject to expansion.

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/



reply via email to

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