From: Phil Pennock <Phil.Pennock@globnix.org>
To: zsh-users@sunsite.dk
Subject: Re: aliases not getting expanded inside functions?
Date: Fri, 3 Jan 2003 18:44:55 +0100 [thread overview]
Message-ID: <20030103184455.A5692@globnix.org> (raw)
In-Reply-To: <15893.50996.646711.184945@fisica.ufpr.br>; from carlos@fisica.ufpr.br on Fri, Jan 03, 2003 at 03:24:04PM -0200
[-- Attachment #1: Type: text/plain, Size: 1812 bytes --]
On 2003-01-03 at 15:24 -0200, Carlos Carvalho wrote:
> Phil Pennock (Phil.Pennock@globnix.org) wrote on 3 January 2003 16:45:
> >% bar='Fred Bloggs'
> >% foo='bar'
> >% function escr { print ${(P)foo} }
> >% escr
> >Fred Bloggs
> >
> >Is the above sufficient?
>
> Unfortunately no, because I don't need it only for printing, but for
> referencing as well. I have an array and I'd like to access the
> elements by more meaningful names, so I tried to do
>
> % alias -g guess_what='array[1]', etc.
>
> Your suggestion doesn't work however when an assignment has to be made
> to guess_what.
>
> >You might wish to read zshexpn(1), since there are many other weird and
> >wonderful ways in which zsh can pervert your data on demand.
>
> I did but didn't see this possibility. In fact I still don't see...
> What's the relation between recognizing the same escape sequences as
> print and making a substitution? I'd be grateful for an explanation.
print is merely what was used for showing the results. The variable
substitution does not rely upon print.
% set -A array alpha beta gamma delta epsilon zeta
% guess_what='array[3]'
% echo ${(P)guess_what}
gamma
% guess_what='array[4]'
% echo ${(P)guess_what}
delta
% guess_what='array[1]'
% for i in $(perl -le "print foreach split //, '${(P)guess_what}'") ; echo $i
a
l
p
h
a
%
My suggestion appears to work, independent of echo/print. :^)
I think that you're confusing "print -P", which recognises the same
escape sequences as are used in prompt substitution, with the parameter
expansion flag 'P', which is described in zshexpn(1).
--
"We've got a patent on the conquering of a country through the use of force.
We believe in world peace through extortionate license fees." -- Andy Forster
[-- Attachment #2: Type: application/pgp-signature, Size: 187 bytes --]
next prev parent reply other threads:[~2003-01-03 17:45 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-01-03 15:31 Carlos Carvalho
2003-01-03 15:39 ` Zefram
2003-01-03 15:45 ` Phil Pennock
2003-01-03 17:24 ` Carlos Carvalho
2003-01-03 17:44 ` Phil Pennock [this message]
2003-01-03 18:10 ` Carlos Carvalho
2003-01-03 18:54 ` Zefram
2003-01-06 8:29 ` Carlos Carvalho
2003-01-06 12:54 ` Bart Schaefer
2003-01-11 3:19 ` Carlos Carvalho
2003-01-11 18:40 ` Bart Schaefer
2003-01-13 17:59 ` Carlos Carvalho
2003-01-13 18:48 ` Bart Schaefer
2003-01-13 21:40 ` Carlos Carvalho
2003-01-14 5:10 ` Bart Schaefer
2003-01-14 11:44 ` Roman Neuhauser
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=20030103184455.A5692@globnix.org \
--to=phil.pennock@globnix.org \
--cc=zsh-users@sunsite.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).