Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: convolutions
- X-seq: zsh-users 20908
- From: Ray Andrews <rayandrews@xxxxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Subject: Re: convolutions
- Date: Fri, 06 Nov 2015 22:33:56 -0800
- Cc: Zsh Users <zsh-users@xxxxxxx>
- In-reply-to: <CAH+w=7bzDJV5bLSr3=bVkAoOm-Yov3DU9w58eqr6daJFCNvw-w@mail.gmail.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <563D5ED5.1070102@eastlink.ca> <CAH+w=7bzDJV5bLSr3=bVkAoOm-Yov3DU9w58eqr6daJFCNvw-w@mail.gmail.com>
On 11/06/2015 09:38 PM, Bart Schaefer wrote:
On Fri, Nov 6, 2015 at 6:15 PM, Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
Gentlemen:
echo "$(eval echo "\${$(cat in_file)}")" >! out_file
That's the best I've been able to do expanding color variables, eg. " ${red}
" into their native " \e[31;1m " in a file.
Just as an aside, this is the second code example you've posted
recently that can't possibly work in practice. I can only assume
you're mis-transcribing in an attempt to simplify whatever your real
code is.
I did indeed edit it a bit. Here's the pasted actual test file:
test2 ()
{
echo "$(eval echo "\${$(cat junk1)}")" >! junk2
cat junk2
}
... which works as advertised.
If I understand this correctly, you have a file that contains text
which looks like
The following ${fg[red]}text is red${reset_color} and this is not
and you want to end up with the variables expanded in out_file as the
actual escape sequences?
print -R "${(e)$(<in_file)}" >| out_file
Does the trick, thanks, it's no shorter, but much more respectable.
print has many tricks up it's sleeve.
Of course that will also replace other possible expansions that may
appear in the text of in_file. If you really want to replace exactly
and only the specific references to color variables, you needs
something like Zyx's sed expression.
Yeah, my snippet would have the same issue so that's fine. It seems so
laborious tho. Too bad there wasn't some way of forcing expansions in a
prescribed order to avoid the echoing and evaling.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author