From owner-freebsd-questions Tue Feb 19 22: 8:41 2002 Delivered-To: freebsd-questions@freebsd.org Received: from mishkei.org.il (ghost2.fortress.mad.co.il [62.128.62.12]) by hub.freebsd.org (Postfix) with SMTP id 8D8B937B400 for ; Tue, 19 Feb 2002 22:08:35 -0800 (PST) Received: (qmail 28735 invoked from network); 20 Feb 2002 06:07:19 -0000 Received: from 212.116.170.38.knet.co.il (HELO dhcp-251) (212.116.170.38) by 0 with SMTP; 20 Feb 2002 06:07:19 -0000 Subject: Re: Bourne shell programming problem From: Gilad Rom To: Eric Boucher Cc: FreeBSD-Questions In-Reply-To: <20020220060104.49523.qmail@web9407.mail.yahoo.com> References: <20020220060104.49523.qmail@web9407.mail.yahoo.com> Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Mailer: Evolution/1.0.1 Date: 20 Feb 2002 08:08:27 +0200 Message-Id: <1014185310.23322.14.camel@dhcp-251.meshek.eh> Mime-Version: 1.0 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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 On Wed, 2002-02-20 at 08:01, 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. > > Can somebody help me on this one? I hope I'm > sufficiently clear. > > Thanks > > Eric > > __________________________________________________ > Do You Yahoo!? > Yahoo! Sports - Coverage of the 2002 Olympic Games > http://sports.yahoo.com > > To Unsubscribe: send mail to majordomo@FreeBSD.org > with "unsubscribe freebsd-questions" in the body of the message > To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message