From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29718 invoked by alias); 7 Nov 2015 02:55:08 -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: 20904 Received: (qmail 13084 invoked from network); 7 Nov 2015 02:55:07 -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,FREEMAIL_FROM, T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1446864557; bh=SJWbswWIltTrqc9EIjMh947JIxCOXdLoiFKsVdusp1o=; h=From:To:In-Reply-To:References:Subject:Date; b=CsLSyrjEvwdcGLPKfPB8tmSBk6qSQeF3JUdYzborPtmA6JSNEK0LteNs/cEru/VRW sUAYzUQ39AsZqBug+FUd61NL9yQ7q0ydyiciD5iGPXZu5WoK2aN7wTxvAg0tBIzJkn /aAxfEhlcT5PMb3Z2ZmSv1IfpcFEXknRbELBWo3k= From: ZyX To: Ray Andrews , Zsh Users In-Reply-To: <563D5ED5.1070102@eastlink.ca> References: <563D5ED5.1070102@eastlink.ca> Subject: Re: convolutions MIME-Version: 1.0 Message-Id: <706021446864556@web9j.yandex.ru> X-Mailer: Yamail [ http://yandex.ru ] 5.0 Date: Sat, 07 Nov 2015 05:49:16 +0300 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=utf-8 07.11.2015, 05:17, "Ray Andrews" : > 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. It's not a prize > winner as far as zsh obfuscation goes, still, can it be done more > simply? Also, I'd not be surprised to learn that there's one of those > ancient little utilities that already does that: > >      cat in_file | ancient_utility > outfile > > is there? “Ancient utility” is called `sed`. Specifically you are able to substitute text with the result of the evaluation of the shell code: echo '${red}red' | sed -r 's/\$\{(\w+)\}/zsh -c ''echo ${(%%):-%F{\1}}''/e' Note: sed uses /bin/sh for /e and not $SHELL, so you must call zsh explicitly. Note 2: see “SIMPLE PROMPT ESCAPES” (specifically `%F`) in `man zshmisc`. See “PARAMETER EXPANSION”/“Parameter Expansion Flags” in `man zshexpn` (specifically `%` flag). See `man zshoptions`, option `RCQUOTES` if you are wondering why I wrote `''`. You may also do the same thing with almost every other script language. But while in perl this is mostly as verbose as in sed, most other are less oriented on text processing and will be more verbose. Also sed and awk are rather standard, perl and python also are to a less extent, everything else better be avoided in shell scripts.