From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 830 invoked from network); 6 Sep 2001 06:42:59 -0000 Received: from sunsite.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 6 Sep 2001 06:42:59 -0000 Received: (qmail 22883 invoked by alias); 6 Sep 2001 06:42:42 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 4201 Received: (qmail 22869 invoked from network); 6 Sep 2001 06:42:40 -0000 From: Bart Schaefer Message-Id: <1010906064113.ZM15455@candle.brasslantern.com> Date: Thu, 6 Sep 2001 06:41:13 +0000 In-Reply-To: <999739397.219670.15579.nullmailer@bozar.algorithm.com.au> Comments: In reply to Andre Pang "running a command multiple times on a glob pattern" (Sep 6, 11:23am) References: <999739397.219670.15579.nullmailer@bozar.algorithm.com.au> X-Mailer: Z-Mail (5.0.0 30July97) To: Andre Pang , zsh-users@sunsite.dk Subject: Re: running a command multiple times on a glob pattern MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Sep 6, 11:23am, Andre Pang wrote: } } i'm thinking that it'd be really handy to have some sort of } shell construct that looks like } } tar zxvf {{*.tar.gz}} } } which basically expands to } } for i in *.tar.gz; do tar zxvf $i; done There are all sorts of ways to do this. Here's one: setopt short_loops alias with='for WITH in' function call { emulate -L zsh; $* $WITH } (Pick different words than "call" and "with" if you like.) Now you write with *.tar.gz; call tar zxvf The drawback being that it doesn't nest, because there's only one loop variable. As you can tell, short_loops are pretty terse to begin with; it's only two more characters to write for i in *.tar.gz; tar zxvf $i but do whatever floats your boat. Another possibility is: function call { emulate -L zsh local a=$'\0\1' a=$argv[(I)$a] # $'...' doesn't work in subscripts if (( a )); then local -a cmd args cmd=($argv[1,a-1]) args=($argv[a+1,-1]) for a in $args; do $cmd $a; done fi } alias -g with=$'\0\1' (Use a string more unlikely than $'\0\1' if you find it necessary.) Now you can say call tar zxvf with *.tar.gz and if you need to pass "with" as an argument, you just quote it. zsh% call echo with this "with" that this with that You can even nest this, though it doesn't work precisely as you might expect: zsh% call call echo this and that with those and with some more this and that those this and that and this and that some this and that those this and that and this and that more I could go on, but I won't. -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.brasslantern.com Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net