From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23697 invoked from network); 27 Mar 1999 20:51:19 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 27 Mar 1999 20:51:19 -0000 Received: (qmail 28736 invoked by alias); 27 Mar 1999 20:50:38 -0000 Mailing-List: contact zsh-users-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 2247 Received: (qmail 28727 invoked from network); 27 Mar 1999 20:50:35 -0000 From: "Bart Schaefer" Message-Id: <990327125025.ZM2187@candle.brasslantern.com> Date: Sat, 27 Mar 1999 12:50:25 -0800 In-Reply-To: <199903220807.JAA02960@beta.informatik.hu-berlin.de> Comments: In reply to Sven Wischnowsky "Re: param modifier to strip _all_ suffixes?" (Mar 22, 9:07am) References: <199903220807.JAA02960@beta.informatik.hu-berlin.de> X-Mailer: Z-Mail (4.0b.820 20aug96) To: zsh-users@sunsite.auc.dk Subject: Re: param modifier to strip _all_ suffixes? MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Mar 22, 9:07am, Sven Wischnowsky wrote: } Subject: Re: param modifier to strip _all_ suffixes? } } Sweth Chandramouli wrote: } } > is there a token modifier like :r that strips _all_ } > suffixes of the form `.xxx', rather than just the last one--the } > equivalent of ${PARAM%%.*} instead of just ${PARAM%.*}? } } Combine it with `f': } } % a=foo.a.b.c } % echo $a:fr } foo To summarize a private discussion that Sweth and I had about this ... First, note that ${param:fr} and ${param%%.*} are NOT equivalent when the string being operated upon begins with a dot. zsh% x=.foo.bar.baz zsh% echo ${x:fr} .foo zsh% echo ${x%%.*} zsh% To get the equivalent of :fr with pattern matching, you have to do some silly stuff like this: zsh% echo ${${${(M)x#(?|.)*.}:-$x}%.} .foo Unfortunately, :f and a few other operators do not apply to history expansions. There are two entirely separate bits of code implementing the modifiers for parameters and those for history; no one has ever bothered to extend the history modifier code beyond the initial csh compatibility stuff. I've forgotten the technical reason why there can't be a single string-chopping function that implements all the colon-modifiers and is simply used for both history and parameters. A workaround for this is to employ a scratch variable to capture the history expansion: zsh% cp .foo.bar.baz .florp.gletch.ick zsh% echo copied ${${x::="!:1"}:fr} to ${${x::="!$"}:fr} That works for performing pattern substitutions on history as well, of course, but that gets ugly pretty fast. A last observation is that this stuff probably isn't as necessary in history anyway, as you can always hit TAB to expand the history ref and then edit it. You're never going to be writing a script that uses the history. Nevertheless, consistency would be nice. -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.brasslantern.com