From owner-freebsd-questions Fri Dec 17 21:12:52 1999 Delivered-To: freebsd-questions@freebsd.org Received: from dorifer.heim3.tu-clausthal.de (dorifer.heim3.tu-clausthal.de [139.174.243.252]) by hub.freebsd.org (Postfix) with ESMTP id 05D9C14C94 for ; Fri, 17 Dec 1999 21:12:46 -0800 (PST) (envelope-from olli@dorifer.heim3.tu-clausthal.de) Received: (from olli@localhost) by dorifer.heim3.tu-clausthal.de (8.8.8/8.8.8) id GAA28012; Sat, 18 Dec 1999 06:12:33 +0100 (CET) (envelope-from olli) Date: Sat, 18 Dec 1999 06:12:33 +0100 (CET) From: Oliver Fromme Message-Id: <199912180512.GAA28012@dorifer.heim3.tu-clausthal.de> To: freebsd-questions@freebsd.org Subject: Re: howto tokenize string in sh Cc: keramida@ceid.upatras.gr Reply-To: freebsd-questions@freebsd.org Organization: Administration TU Clausthal MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Newsreader: TIN [version 1.2 RZTUC(3) PL2] Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Giorgos Keramidas wrote in list.freebsd-questions: > sed(1) is your friend. use something like: > > VARIABLE="`echo $DIRNAME | sed -e 's@/@ @g'`" > > then you can always use > > set $VARIABLE That's not a good idea, because it will break if the pathname already contains spaces. Another better possibility is to modify the shell's $IFS: OLD_IFS="$IFS" IFS=/ set x $VARIABLE shift IFS="$OLD_IFS" Note the "x" and the shift. This prevents breakage of the contents of $VARIABLE begins with a "-". And do not forget to reset $IFS to the old value, otherwise you ight run into very strange effects. ;-) > and use $1, $2 and so on for the parts of it, or something like: > > for component in $VARIABLE ;do > echo $component > done Regards Oliver -- Oliver Fromme, Leibnizstr. 18/61, 38678 Clausthal, Germany (Info: finger userinfo:olli@dorifer.heim3.tu-clausthal.de) "In jedem Stück Kohle wartet ein Diamant auf seine Geburt" (Terry Pratchett) To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message