Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: bar='#pat'; ${foo/$bar/...} problem
- X-seq: zsh-workers 6001
- From: "Bart Schaefer" <schaefer@xxxxxxxxxxxxxxxx>
- To: "ZSH workers mailing list" <zsh-workers@xxxxxxxxxxxxxx>
- Subject: Re: bar='#pat'; ${foo/$bar/...} problem
- Date: Fri, 2 Apr 1999 02:39:51 -0800
- In-reply-to: <002e01be7c48$968d8860$21c9ca95@xxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxxxxxx; run by ezmlm
- References: <002e01be7c48$968d8860$21c9ca95@xxxxxxxxxxxxxxx>
On Apr 1, 6:04pm, Andrej Borsenkow wrote:
} Subject: bar='#pat'; ${foo/$bar/...} problem
}
} It seems to be impossible to specify `#' (and probably `%') as part of the
} replaced pattern:
What you mean here is, specify left-anchored or right-anchored patterns,
right? In that case, the # or % is not "part of the pattern", it's part
of the ${...} syntax. The rest is just a glob pattern and doesn't have
any built-in notion of "anchored." So really there are three:
${foo/pat/rep} pat --> rep, anywhere in foo
${foo/#pat/rep} pat --> rep, at left of foo
${foo/%pat/rep} pat --> rep, at right of foo
Once you get that, it's easy to see that what you're attempting is the
same as if you did
% bar=('/#xx' '/zz'}
% print ${foo$bar[1]$bar[2]}
which you obviously wouldn't expect to work (I hope).
Now, you might argue that the implementation of /# and /% should be as
if # and % are extensions of the glob syntax, and in fact that is how
it appears to be implemented in bash:
$ foo=xxya
$ bar='#xx'
$ echo ${foo/$bar/zz}
zzya
In the meantime, though, you need an eval step of some kind:
% foo=(xxya xxyb)
% bar=('#xx' 'zz')
% eval print '${foo/'"$bar[1]"'/$bar[2]}'
(Did I get to be article 6000? :-)
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
Messages sorted by:
Reverse Date,
Date,
Thread,
Author