Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 20 Feb 2002 02:00:38 -0500
From:      Jim Conner <jconner@enterit.com>
To:        Gilad Rom <rom_glsa@ein-hashofet.co.il>
Cc:        Eric Boucher <eric_boucher60@yahoo.com>, FreeBSD-Questions <freebsd-questions@FreeBSD.ORG>
Subject:   Re: Bourne shell programming problem
Message-ID:  <5.1.0.14.0.20020220015922.02ba4ca0@mail.enterit.com>
In-Reply-To: <1014185310.23322.14.camel@dhcp-251.meshek.eh>
References:  <20020220060104.49523.qmail@web9407.mail.yahoo.com> <20020220060104.49523.qmail@web9407.mail.yahoo.com>

next in thread | previous in thread | raw e-mail | index | archive | help
At 08:08 02.20.2002 +0200, Gilad Rom wrote:
>What you want to do is harness the power of awk:
>
>var="/toto/tata/foo"
>
>dirs=`echo $var | awk -F '/' '{print $1 $2 $3;}'`
>
>for i in $dirs
>do
>         echo $i
>done
>
>Gilad
>
>
> > 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.
> >

If foo is a file I'd use /usr/bin/basename

var="/toto/tata/foo"
base=$(/usr/bin/basename $var)

- Jim


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?5.1.0.14.0.20020220015922.02ba4ca0>