Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 20 Feb 2002 17:36:19 +0100
From:      Cliff Sarginson <csfbsd@raggedclown.net>
To:        FreeBSD <freebsd-questions@FreeBSD.ORG>
Subject:   Re: Bourne shell programming problem
Message-ID:  <20020220163619.GA3600@raggedclown.net>
In-Reply-To: <20020219234405.V48401@blossom.cjclark.org>
References:  <20020220060104.49523.qmail@web9407.mail.yahoo.com> <20020219234405.V48401@blossom.cjclark.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Feb 19, 2002 at 11:44:05PM -0800, Crist J. Clark wrote:
> On Tue, Feb 19, 2002 at 10:01:04PM -0800, Eric Boucher wrote:
> > Hi everyone,
> > 
> > I'm doing a little bourne shell program that makes
> > something installed automatically on my FreeBSD. But I
> > have a little problem: I want to be able to read every
> > caracter of a variable. For example: Suppose I have a
> > variale named TOTO and the content of TOTO is
> > "/toto/tata/foo". So if I do an echo the ouput is:
> > echo $TOTO
> > /toto/tata/foo
> > 
> > What I'm trying to do is to catch only "/foo" and put
> > it in another variable. So I tought that if someone
> > tell me how to read each caracter, I can loop over
> > each caracter, remember the positition of the last "/"
> > and then take all the caracters after that "/" and put
> > it in a variable.
> 
Here is another:

echo "/toto/tata/foo" | sed "s;/.*/;/;"

Personally I would do it using "basename" in this case, but
previous answers show you that method. Amazingly no-one has
suggested how to do it in "perl" yet .. it must be a perl-freak
holy day :)

-- 
Regards
   Cliff Sarginson -- <csfbsd@raggedclown.net>

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020220163619.GA3600>