From owner-freebsd-questions Tue Feb 19 23:44: 8 2002 Delivered-To: freebsd-questions@freebsd.org Received: from rwcrmhc52.attbi.com (rwcrmhc52.attbi.com [216.148.227.88]) by hub.freebsd.org (Postfix) with ESMTP id 6524837B400 for ; Tue, 19 Feb 2002 23:44:06 -0800 (PST) Received: from blossom.cjclark.org ([12.234.91.48]) by rwcrmhc52.attbi.com (InterMail vM.4.01.03.27 201-229-121-127-20010626) with ESMTP id <20020220074406.DDLA1147.rwcrmhc52.attbi.com@blossom.cjclark.org>; Wed, 20 Feb 2002 07:44:06 +0000 Received: (from cjc@localhost) by blossom.cjclark.org (8.11.6/8.11.6) id g1K7i5I24715; Tue, 19 Feb 2002 23:44:05 -0800 (PST) (envelope-from cjc) Date: Tue, 19 Feb 2002 23:44:05 -0800 From: "Crist J. Clark" To: Eric Boucher Cc: FreeBSD Subject: Re: Bourne shell programming problem Message-ID: <20020219234405.V48401@blossom.cjclark.org> References: <20020220060104.49523.qmail@web9407.mail.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <20020220060104.49523.qmail@web9407.mail.yahoo.com>; from eric_boucher60@yahoo.com on Tue, Feb 19, 2002 at 10:01:04PM -0800 X-URL: http://people.freebsd.org/~cjc/ 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 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. You've gotten a couple of answers, so why not one more? Do it all with builtin sh(1) abilities, $ TOTO=/toto/tata/foo $ echo "/${TOTO##*/}" /foo -- Crist J. Clark | cjclark@alum.mit.edu | cjclark@jhu.edu http://people.freebsd.org/~cjc/ | cjc@freebsd.org To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message