Date: Sat, 18 Dec 1999 06:12:33 +0100 (CET) From: Oliver Fromme <olli@dorifer.heim3.tu-clausthal.de> To: freebsd-questions@freebsd.org Cc: keramida@ceid.upatras.gr Subject: Re: howto tokenize string in sh Message-ID: <199912180512.GAA28012@dorifer.heim3.tu-clausthal.de>
next in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199912180512.GAA28012>