zsh-users
 help / color / mirror / code / Atom feed
* param modifier to strip _all_ suffixes?
@ 1999-03-20 18:50 Sweth Chandramouli
  0 siblings, 0 replies; 3+ messages in thread
From: Sweth Chandramouli @ 1999-03-20 18:50 UTC (permalink / raw)
  To: ZSH Users

	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%.*}?  perhaps,
if there isn't, :R could be given that meaning?

	-- sweth.

-- 
Sweth Chandramouli
IS Coordinator, The George Washington University
<sweth@gwu.edu> / (202) 994 - 8521 (V) / (202) 994 - 0458 (F)
<a href="http://astaroth.nit.gwu.edu/~sweth/disc.html">*</a>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: param modifier to strip _all_ suffixes?
  1999-03-22  8:07 Sven Wischnowsky
@ 1999-03-27 20:50 ` Bart Schaefer
  0 siblings, 0 replies; 3+ messages in thread
From: Bart Schaefer @ 1999-03-27 20:50 UTC (permalink / raw)
  To: zsh-users

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: param modifier to strip _all_ suffixes?
@ 1999-03-22  8:07 Sven Wischnowsky
  1999-03-27 20:50 ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Sven Wischnowsky @ 1999-03-22  8:07 UTC (permalink / raw)
  To: zsh-users


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%.*}?  perhaps,
> if there isn't, :R could be given that meaning?

Combine it with `f':

  % a=foo.a.b.c
  % echo $a:fr
  foo


Bye
 Sven


--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1999-03-27 20:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-03-20 18:50 param modifier to strip _all_ suffixes? Sweth Chandramouli
1999-03-22  8:07 Sven Wischnowsky
1999-03-27 20:50 ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).