zsh-users
 help / color / mirror / code / Atom feed
From: "Bart Schaefer" <schaefer@brasslantern.com>
To: zsh-users@sunsite.auc.dk
Subject: Re: param modifier to strip _all_ suffixes?
Date: Sat, 27 Mar 1999 12:50:25 -0800	[thread overview]
Message-ID: <990327125025.ZM2187@candle.brasslantern.com> (raw)
In-Reply-To: <199903220807.JAA02960@beta.informatik.hu-berlin.de>

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


  reply	other threads:[~1999-03-27 20:51 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-03-22  8:07 Sven Wischnowsky
1999-03-27 20:50 ` Bart Schaefer [this message]
  -- strict thread matches above, loose matches on Subject: below --
1999-03-20 18:50 Sweth Chandramouli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=990327125025.ZM2187@candle.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-users@sunsite.auc.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).