logo       

Re: The IFS variable - a confusing issue. [+POSIX conformance pb]: msg#00247

shells.bash.bugs

Subject: Re: The IFS variable - a confusing issue. [+POSIX conformance pb]

On Sat, Oct 16, 2004 at 03:42:46PM +0200, Enrique Perez-Terron wrote:
[...]
> You could try the following:
>
> 2 IFS=: eval "list=(\$PATH)"
> 3 for d in "${list[@]}"; do
>
> (Sorry for the massive punctuation needed.)
>
> It has the advantage of not changing IFS other than for the eval
> command.

Well, you shouldn't rely on that, as in POSIX mode and in other
/POSIX/ shells such as ksh or zsh in sh mode or dash (and also
the Bourne shell), it is not true:

http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_14

2. Variable assignments specified with special built-in
utilities remain in effect after the built-in completes;
this shall not be the case with a regular built-in or other
utility.
[eval is "special builtin"].

You should be able to do:

IFS=: command eval 'list=($PATH)'

as "command" is not a special builtin. However, it works with
ksh or zsh but doesn't seem to work with bash --posix (3.0.13,
bug?).

$ /usr/local/bin/bash --posix -c '
> IFS=: command eval "list=(\$PATH)"; echo "$IFS"'
:
$

--
Stephane


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise