From owner-freebsd-questions Wed Feb 20 8:36:24 2002 Delivered-To: freebsd-questions@freebsd.org Received: from post.mail.nl.demon.net (post-11.mail.nl.demon.net [194.159.73.21]) by hub.freebsd.org (Postfix) with ESMTP id 9D56B37B402 for ; Wed, 20 Feb 2002 08:36:21 -0800 (PST) Received: from [212.238.194.207] (helo=mailhost.raggedclown.net) by post.mail.nl.demon.net with esmtp (Exim 3.33 #1) id 16dZjA-0001WO-00 for freebsd-questions@FreeBSD.ORG; Wed, 20 Feb 2002 16:36:20 +0000 Received: from angel.raggedclown.net (angel.raggedclown.intra [192.168.1.7]) by mailhost.raggedclown.net (Ragged Clown Mail Gateway [buffy]) with ESMTP id 3F87613040 for ; Wed, 20 Feb 2002 17:36:19 +0100 (CET) Received: by angel.raggedclown.net (Ragged Clown Host [angel], from userid 6002) id 4EC8222590; Wed, 20 Feb 2002 17:36:19 +0100 (CET) Date: Wed, 20 Feb 2002 17:36:19 +0100 From: Cliff Sarginson To: FreeBSD Subject: Re: Bourne shell programming problem Message-ID: <20020220163619.GA3600@raggedclown.net> References: <20020220060104.49523.qmail@web9407.mail.yahoo.com> <20020219234405.V48401@blossom.cjclark.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20020219234405.V48401@blossom.cjclark.org> User-Agent: Mutt/1.3.27i 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 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 -- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message