zsh-users
 help / color / mirror / code / Atom feed
* Re: Notes on bash(1)
@ 1998-12-09 16:19 Jason Price
  1998-12-09 16:38 ` Michael Barnes
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Jason Price @ 1998-12-09 16:19 UTC (permalink / raw)
  To: zsh-users

>From zsh-workers:

(Quoting got screwed up... Sorry...)

Forwarded message:
> > * ${parameter/pattern/string} and ${parameter//pattern/string}
> >   pattern is expanded as per pathname expansion.  [munch]
>
> [munch]
> Maybe it can be done quite simply by upgrading the extra flags Sven
> added for # and % to match internal bits of a parameter's value.

there are a heck of a lot of ${...} modifiers that are wonderfully useful,
but in my searching through the man pages, I havn't found an equivelent to
basename /usr/local/bin/mumble -> mumble.  I need to pull the basename out
of path strings quite offten, and I'd like to do so in shell.

Is this ... (wait, this is zsh) How can I do this?

Jason

-- 
Faith is not a matter of questions.      Jason Price
Faith is a matter of answers.            jprice@gatech.edu
More to the point, one answer:           Theta Xi, Beta Alpha, 449
"Yes, Lord."


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

* Re: Notes on bash(1)
  1998-12-09 16:19 Notes on bash(1) Jason Price
@ 1998-12-09 16:38 ` Michael Barnes
  1998-12-09 17:17 ` Swen Thuemmler
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Michael Barnes @ 1998-12-09 16:38 UTC (permalink / raw)
  To: zsh-users

On Wed, Dec 09, 1998 at 11:19:27AM -0500, Jason Price wrote:
> >From zsh-workers:
> 
> (Quoting got screwed up... Sorry...)
> 
> Forwarded message:
> > > * ${parameter/pattern/string} and ${parameter//pattern/string}
> > >   pattern is expanded as per pathname expansion.  [munch]
> >
> > [munch]
> > Maybe it can be done quite simply by upgrading the extra flags Sven
> > added for # and % to match internal bits of a parameter's value.
> 
> there are a heck of a lot of ${...} modifiers that are wonderfully useful,
> but in my searching through the man pages, I havn't found an equivelent to
> basename /usr/local/bin/mumble -> mumble.  I need to pull the basename out
> of path strings quite offten, and I'd like to do so in shell.
> 
> Is this ... (wait, this is zsh) How can I do this?


~squid/logs foo=/usr/local/bin/mumble
~squid/logs echo $foo[(ws:/:)-1]      
mumble
~squid/logs foo=/usr/local/bin/mumble/
~squid/logs echo $foo[(ws:/:)-1]
mumble


This makes foo an array with the word separator `/' and gives the last
element in that array.

I am sure there are otherways to do this but this works for me.

Mike


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

* Re: Notes on bash(1)
  1998-12-09 16:19 Notes on bash(1) Jason Price
  1998-12-09 16:38 ` Michael Barnes
@ 1998-12-09 17:17 ` Swen Thuemmler
  1998-12-09 17:23 ` Bart Schaefer
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Swen Thuemmler @ 1998-12-09 17:17 UTC (permalink / raw)
  To: Jason Price; +Cc: zsh-users

On Wed, 9 Dec 1998, Jason Price wrote:

> there are a heck of a lot of ${...} modifiers that are wonderfully useful,
> but in my searching through the man pages, I havn't found an equivelent to
> basename /usr/local/bin/mumble -> mumble.  I need to pull the basename out
> of path strings quite offten, and I'd like to do so in shell.
> 
> Is this ... (wait, this is zsh) How can I do this?

Well, it is in the info-pages, section on modifiers. Excerpt:
`h'
     Remove a trailing pathname component, leaving the head.

`r'
     Remove a trailing suffix of the form ``.'XXX', leaving the
     basename.

`e'
     Remove all but the suffix.

`t'
     Remove all leading pathname components, leaving the tail.
[...]

So:

swen@kreta <~>: foo=/usr/local/bin/mumble
swen@kreta <~>: echo ${foo:t}
mumble
swen@kreta <~>: 

Hope this helps.

--Swen



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

* Re: Notes on bash(1)
  1998-12-09 16:19 Notes on bash(1) Jason Price
  1998-12-09 16:38 ` Michael Barnes
  1998-12-09 17:17 ` Swen Thuemmler
@ 1998-12-09 17:23 ` Bart Schaefer
  1998-12-09 17:44 ` Paul Lew
  1998-12-10 10:45 ` Bruce Stephens
  4 siblings, 0 replies; 6+ messages in thread
From: Bart Schaefer @ 1998-12-09 17:23 UTC (permalink / raw)
  To: Jason Price, zsh-users

On Dec 9, 11:19am, Jason Price wrote:
} Subject: Re: Notes on bash(1)
}
} there are a heck of a lot of ${...} modifiers that are wonderfully useful,
} but in my searching through the man pages, I havn't found an equivelent to
} basename /usr/local/bin/mumble -> mumble.  I need to pull the basename out
} of path strings quite offten, and I'd like to do so in shell.
} 
} Is this ... (wait, this is zsh) How can I do this?

	${${anything::=/usr/local/bin/mumble}:t}

where "anything" is any variable name whose value you don't mind replacing
with the string "/usr/local/bin/mumble".  E.g.:

zsh% echo ${${filename::=/usr/local/bin/mumble}:t}
mumble
zsh% echo $filename
/usr/local/bin/mumble
zsh%


-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


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

* Re: Notes on bash(1)
  1998-12-09 16:19 Notes on bash(1) Jason Price
                   ` (2 preceding siblings ...)
  1998-12-09 17:23 ` Bart Schaefer
@ 1998-12-09 17:44 ` Paul Lew
  1998-12-10 10:45 ` Bruce Stephens
  4 siblings, 0 replies; 6+ messages in thread
From: Paul Lew @ 1998-12-09 17:44 UTC (permalink / raw)
  To: Jason Price; +Cc: zsh-users

>>>>> "Jason" == Jason Price <gt5076c@cad.gatech.edu> writes:

    Jason> there are a heck of a lot of ${...} modifiers that are
    Jason> wonderfully useful, but in my searching through the man
    Jason> pages, I havn't found an equivelent to basename
    Jason> /usr/local/bin/mumble -> mumble.  I need to pull the
    Jason> basename out of path strings quite offten, and I'd like to
    Jason> do so in shell.

    Jason> Is this ... (wait, this is zsh) How can I do this?

$ foo=/usr/local/bin/zsh-3.1.5
$ echo $foo:h		-- head
/usr/local/bin

$ echo $foo:t		-- tail
zsh-3.1.5

$ echo $foo:r		-- root
/usr/local/bin/zsh-3.1

$ echo $foo:e		-- extension
5

Just like csh can do.

					-- Paul  12/09/98  12:43 PM --


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

* Re: Notes on bash(1)
  1998-12-09 16:19 Notes on bash(1) Jason Price
                   ` (3 preceding siblings ...)
  1998-12-09 17:44 ` Paul Lew
@ 1998-12-10 10:45 ` Bruce Stephens
  4 siblings, 0 replies; 6+ messages in thread
From: Bruce Stephens @ 1998-12-10 10:45 UTC (permalink / raw)
  To: zsh-users

Jason Price <gt5076c@cad.gatech.edu> writes:

> there are a heck of a lot of ${...} modifiers that are wonderfully useful,
> but in my searching through the man pages, I havn't found an equivelent to
> basename /usr/local/bin/mumble -> mumble.  I need to pull the basename out
> of path strings quite offten, and I'd like to do so in shell.
> 
> Is this ... (wait, this is zsh) How can I do this?

Personally, I use ## and %% operators for this:

	i=/usr/local/bin/mumble
	echo ${i##*/}

prints mumble.  This also works in bash and ksh.


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

end of thread, other threads:[~1998-12-10 23:42 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-12-09 16:19 Notes on bash(1) Jason Price
1998-12-09 16:38 ` Michael Barnes
1998-12-09 17:17 ` Swen Thuemmler
1998-12-09 17:23 ` Bart Schaefer
1998-12-09 17:44 ` Paul Lew
1998-12-10 10:45 ` Bruce Stephens

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).