From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14632 invoked from network); 6 Apr 2001 16:54:41 -0000 Received: from sunsite.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 6 Apr 2001 16:54:41 -0000 Received: (qmail 1074 invoked by alias); 6 Apr 2001 16:54:30 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 3808 Received: (qmail 1062 invoked from network); 6 Apr 2001 16:54:29 -0000 From: "Bart Schaefer" Message-Id: <1010406165353.ZM12264@candle.brasslantern.com> Date: Fri, 6 Apr 2001 16:53:53 +0000 In-Reply-To: <20010406151348.A27201@greux.loria.fr> Comments: In reply to Vincent Lefevre "Parameter expansion: tr?" (Apr 6, 3:13pm) References: <20010406151348.A27201@greux.loria.fr> X-Mailer: Z-Mail (5.0.0 30July97) To: zsh-users@sunsite.dk, Vincent Lefevre Subject: Re: Parameter expansion: tr? MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Apr 6, 3:13pm, Vincent Lefevre wrote: } Subject: Parameter expansion: tr? } } I've seen how one can do a string substitution in a parameter expansion, } but how can I do a tr, e.g. to swap the "." and "/" characters? } } Is there a simple way to do that, or do I need associative arrays? The following requires 3.1.9 or later: function ztr { setopt extendedglob noshwordsplit local chunk='' while read -u0k 4096 chunk; do print -Rn ${chunk//(#b)([$1])/${2[${1[(I)$match]}]}} chunk='' done # "read -k" will exit nonzero on the last partial chunk, print it (( $#chunk )) && print -Rn ${chunk//(#b)([$1])/${2[${1[(I)$match]}]}} } % ztr "abcde ." "NOPQR-/" <