From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6305 invoked by alias); 7 Nov 2015 06:34:01 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 20908 Received: (qmail 8895 invoked from network); 7 Nov 2015 06:34:00 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.0 X-Authority-Analysis: v=2.1 cv=X+5rdgje c=1 sm=1 tr=0 a=NKvc7L9z7/b0bXwZ1ZmuGA==:117 a=NKvc7L9z7/b0bXwZ1ZmuGA==:17 a=IkcTkHD0fZMA:10 a=fjQKfxOY2nBXbPYIytYA:9 a=QEXdDO2ut3YA:10 Message-id: <563D9B54.9010604@eastlink.ca> Date: Fri, 06 Nov 2015 22:33:56 -0800 From: Ray Andrews User-Agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Icedove/31.7.0 MIME-version: 1.0 To: Bart Schaefer Cc: Zsh Users Subject: Re: convolutions References: <563D5ED5.1070102@eastlink.ca> In-reply-to: Content-type: text/plain; charset=utf-8; format=flowed Content-transfer-encoding: 7bit On 11/06/2015 09:38 PM, Bart Schaefer wrote: > On Fri, Nov 6, 2015 at 6:15 PM, Ray Andrews 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)$(| 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. >