zsh-workers
 help / color / mirror / code / Atom feed
* Re: Bad expansion
@ 2002-01-22  0:17 DervishD
  0 siblings, 0 replies; 7+ messages in thread
From: DervishD @ 2002-01-22  0:17 UTC (permalink / raw)
  To: raul, schaefer; +Cc: zsh-workers

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1351 bytes --]

    Hello Bart :)

>> >>    # Bad substitution
>> >>    echo ${${testing[1]}_VALUE}
>> >echo ${(e):-\$${testing[1]}_VALUE}
>> >The :-\ is a smiley that means "maybe there ought to be a neater way".
>>     Are you joking?
>Yes, he is.

    I knew, just a rethoric question ;))))

>>     "Expand <NULL> identifier, and, if it is not defined or missing
>> (which is true), expand the other thing, that is, \$${testing[1]}_VALUE"
>Almost.  You forgot about the (e).  The whole expression means:

    Oh, I see O:)) The expansions... I was misguided by the smiley XDD

>>     Seriously: why am I having the 'bad substitution' error? What am
>> I doing wrong?. This interest me more than the solution.
>Anything that looks like ${${...}} is called a "nested substitution".  The
>stuff inside the outermost ${...} can take one of two forms:
>(1) it can be the name of a parameter (in which case the substitution is
>    not nested, of course), plus an optional [...] subscript;
>(2) it can be another ${...} substitution expression plus an optional
>    subscript.

    Crystal clear now. I didn't understand the rules for nested
substitution on the zsh manual. Thanks a lot :)

    You are of invaluable help, truly. It's people like Zefram and
you that makes me proud of using Linux, Zsh and all that good free
software out there. You're great.

    Raúl


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Bad expansion
  2002-01-21 19:46 ` DervishD
@ 2002-01-21 21:31   ` Bart Schaefer
  0 siblings, 0 replies; 7+ messages in thread
From: Bart Schaefer @ 2002-01-21 21:31 UTC (permalink / raw)
  To: DervishD; +Cc: zsh-workers

On Jan 21,  8:40pm, DervishD wrote:
> 
> >>    # Bad substitution
> >>    echo ${${testing[1]}_VALUE}
> >echo ${(e):-\$${testing[1]}_VALUE}
> >The :-\ is a smiley that means "maybe there ought to be a neater way".
> 
>     Are you joking?

Yes, he is.

>     "Expand <NULL> identifier, and, if it is not defined or missing
> (which is true), expand the other thing, that is, \$${testing[1]}_VALUE"

Almost.  You forgot about the (e).  The whole expression means:

Expand the unnamed identifier, and, if it is not defined or has an empty
value (which is true), insert \$${testing[1]}_VALUE instead; then perform
parameter expansion, command substitution and arithmetic expansion on the
result.

"The result" is of course a `$' (from `\$') followed by the value of the
${testing[1]} expansion, followed by `_VALUE'.  So if ${testing[1]} is,
for example, `foo', then "the result" is `$foo_VALUE', which is parameter-
expanded because of (e), and gives you what you want.

Using (P) instead of (e) allows you to leave off the `\$', because (P)
means "interpret the result as a parameter name and use the value of
that parameter."  However, with (P), you have to use an extra level of
${...}, because (P) takes effect at a different time in the expansion
process than (e) does.

On Jan 21,  8:46pm, DervishD wrote:
> 
>     Seriously: why am I having the 'bad substitution' error? What am
> I doing wrong?. This interest me more than the solution.

Anything that looks like ${${...}} is called a "nested substitution".  The
stuff inside the outermost ${...} can take one of two forms:

(1) it can be the name of a parameter (in which case the substitution is
    not nested, of course), plus an optional [...] subscript;
(2) it can be another ${...} substitution expression plus an optional
    subscript.

That's all; nothing else.  In ${${testing[1]}_VALUE}, the `_VALUE' part
is neither part of the inner ${...} substitution, nor is it a subscript,
so it can't be there.  In ${:-${testing[1]}_VALUE}, the `_VALUE' becomes
part of the outer ${...}, so then it's OK.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Bad expansion
@ 2002-01-21 19:46 ` DervishD
  2002-01-21 21:31   ` Bart Schaefer
  0 siblings, 1 reply; 7+ messages in thread
From: DervishD @ 2002-01-21 19:46 UTC (permalink / raw)
  To: raul, schaefer; +Cc: zsh-workers

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 552 bytes --]

    Hi Bart :))

>} >    # Bad substitution
>} >    echo ${${testing[1]}_VALUE}
>} echo ${(e):-\$${testing[1]}_VALUE}
>} The :-\ is a smiley that means "maybe there ought to be a neater way".
>There's also
>	echo ${(P)${:-${testing[1]}_VALUE}}
>but I don't know whether that can be considered "neater."

    Obviously, the Zefram's solution, which has a smiley XDDD

    Seriously: why am I having the 'bad substitution' error? What am
I doing wrong?. This interest me more than the solution.

    And thanks a lot for your solution too :))

    Raúl


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Bad expansion
@ 2002-01-21 19:40 DervishD
  2002-01-21 19:46 ` DervishD
  0 siblings, 1 reply; 7+ messages in thread
From: DervishD @ 2002-01-21 19:40 UTC (permalink / raw)
  To: raul, zefram; +Cc: zsh-workers

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 696 bytes --]

    Hello Zefram :))

>>    # Bad substitution
>>    echo ${${testing[1]}_VALUE}
>echo ${(e):-\$${testing[1]}_VALUE}
>The :-\ is a smiley that means "maybe there ought to be a neater way".

    Are you joking? XDD It works, but, AFAIK, this (apart from the
obvious smiley) means:

    "Expand <NULL> identifier, and, if it is not defined or missing
(which is true), expand the other thing, that is, \$${testing[1]}_VALUE"

    But, why? I mean, maybe there ought to be a neater way ;)))

    Really, I'm not an expert about parameter expansion. Just the
simple fact that you have provided me a solution is magic for me.

    Thanks a lot Zefram :)) And nice smile-like solution ;)))))

    Raúl


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Bad expansion
  2002-01-21 14:51 ` Zefram
@ 2002-01-21 17:12   ` Bart Schaefer
  0 siblings, 0 replies; 7+ messages in thread
From: Bart Schaefer @ 2002-01-21 17:12 UTC (permalink / raw)
  To: DervishD; +Cc: Zsh

On Jan 21,  2:51pm, Zefram wrote:
} Subject: Re: Bad expansion
}
} DervishD wrote:
} >    # Bad substitution
} >    echo ${${testing[1]}_VALUE}
} 
} echo ${(e):-\$${testing[1]}_VALUE}
} 
} The :-\ is a smiley that means "maybe there ought to be a neater way".

There's also

	echo ${(P)${:-${testing[1]}_VALUE}}

but I don't know whether that can be considered "neater."

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Bad expansion
@ 2002-01-21 14:56 DervishD
  2002-01-21 14:51 ` Zefram
  0 siblings, 1 reply; 7+ messages in thread
From: DervishD @ 2002-01-21 14:56 UTC (permalink / raw)
  To: Zsh

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 908 bytes --]

    Hello all :))

    I have a doubt with parameter expansion, because I'm getting an
error of 'bad substitution' on the following code

    # Let's assume I have the following array
    testing=(one two three)
    export testing
    export one_VALUE=DD

    # The following line correctly outputs 'one_VALUE'
    echo $testing[1]_VALUE

    # Idem
    echo ${testing[1]}_VALUE

    # Bad substitution
    echo ${${testing[1]}_VALUE}

    The problem is that I will need even further expansion, because I
want to do 'echo ${(P)${testing[1]}_VALUE}', that is, I want the
output of one_VALUE. And, because the rest of the script, I cannot
use directly the value of one_VALUE in the array 'testing'.

    What am I doing wrong? Just in case, I want to do what is
achieved under Bash with ${!${testing[0]}_VALUE}. Please note that
arrays start at 0 under Bash, not at 1.

    Thanks a lot in advance

    Raúl


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Bad expansion
  2002-01-21 14:56 DervishD
@ 2002-01-21 14:51 ` Zefram
  2002-01-21 17:12   ` Bart Schaefer
  0 siblings, 1 reply; 7+ messages in thread
From: Zefram @ 2002-01-21 14:51 UTC (permalink / raw)
  To: DervishD; +Cc: Zsh

DervishD wrote:
>    # Bad substitution
>    echo ${${testing[1]}_VALUE}

echo ${(e):-\$${testing[1]}_VALUE}

The :-\ is a smiley that means "maybe there ought to be a neater way".

-zefram


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2002-01-22  0:04 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-01-22  0:17 Bad expansion DervishD
  -- strict thread matches above, loose matches on Subject: below --
2002-01-21 19:40 DervishD
2002-01-21 19:46 ` DervishD
2002-01-21 21:31   ` Bart Schaefer
2002-01-21 14:56 DervishD
2002-01-21 14:51 ` Zefram
2002-01-21 17:12   ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).