zsh-users
 help / color / mirror / code / Atom feed
From: "Bart Schaefer" <schaefer@candle.brasslantern.com>
To: Phil Pennock <phil@psidev.net>, Zsh Users <zsh-users@sunsite.auc.dk>
Subject: Re: expansion of nested parameters
Date: Mon, 22 Nov 1999 20:14:53 +0000	[thread overview]
Message-ID: <991122201453.ZM23495@candle.brasslantern.com> (raw)
In-Reply-To: <19991122190225.A8613@psidev.net>

On Nov 22,  7:02pm, Phil Pennock wrote:
} Subject: expansion of nested parameters
}
} This is with zsh-3.0.7:
} -----------------------------< cut here >-------------------------------
} #!/bin/zsh -f
} a=foo
} wib_foo_ble=Wow
} c=\$wib_${a}_ble
} print ${(e)c}
} print ${(e)\$wib_${a}_ble}
} -----------------------------< cut here >-------------------------------
} 
} 1: Why does the second print statement print out the current process ID
}    from $$ instead of printing the same as the first print statement?

${(e)c} means:  Expand ${c}, then apply command substitution etc. to the
result of that expansion.

Hence ${(e)\$wib_${a}_ble} means: Expand ${\$wib_${a}_ble}, then ...

You'll note that ${\$} is the same as ${$} because the command-line parser
strips the backslash before the parameter-name interpreter ever gets around
to looking at it.  ${$} is the same as $$; the rest of the "wib_${a}_ble"
stuff is simply ignored once zsh recognizes $$.

} 2: Is there a way to do this without using an intermediate variable, as
}    I've done with $c and without using eval statements?

Yeah; it's in the FAQ, question 3.22.  What you're asking is a variation:

    print ${(e)a:+\$wib_${a}_ble}

should do it.

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


      parent reply	other threads:[~1999-11-22 20:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-11-22 19:02 Phil Pennock
1999-11-22 19:34 ` Zefram
1999-11-22 20:14 ` Bart Schaefer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=991122201453.ZM23495@candle.brasslantern.com \
    --to=schaefer@candle.brasslantern.com \
    --cc=phil@psidev.net \
    --cc=zsh-users@sunsite.auc.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).