Date: Sat, 22 Feb 1997 15:44:08 -0800 (PST) From: Scott Blachowicz <scott@one.sabami.seaslug.org> To: FreeBSD-gnats-submit@freebsd.org Subject: bin/2803: /bin/sh 'for' statement vs IFS setting problem Message-ID: <199702222344.PAA14709@one.sabami.seaslug.org> Resent-Message-ID: <199702222350.PAA01193@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 2803 >Category: bin >Synopsis: /bin/sh 'for' doesn't token break properly >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-bugs >State: open >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Sat Feb 22 15:50:02 PST 1997 >Last-Modified: >Originator: Scott Blachowicz >Organization: none >Release: FreeBSD 2.1.5-RELEASE >Environment: FreeBSD one.sabami.seaslug.org 2.1.5-RELEASE FreeBSD 2.1.5-RELEASE #0: Thu Sep 26 21:57:44 PDT 1996 root@one.sabami.seaslug.org:/usr/src-CD/sys/compile/SABAMI i386 >Description: It APPEARS as if the IFS characters in the list of tokens to loop over get replaced by blanks after it has already been broken up into tokens instead of before the tokenizing. I ran across this using an autoconf generated configure script (trying to locate a program along a colon-separated list of directory names), so I imagine that others will stumble across this. >How-To-Repeat: I use this test script: #! /bin/sh IFS=' :' for tok in a:b:c do echo $tok done for tok in d e f do echo $tok done which SHOULD output 6 lines of output (letters a-f on separate lines), but what comes out is this: a b c d e f >Fix: 1) filter the list of tokens thru sed to replace the :'s with blanks: for tok in `echo a:b:c | sed 's/:/ /'` do echo $tok done 2) throw an extra "eval" in there: for tok in `eval echo a:b:c` do echo $tok done >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199702222344.PAA14709>