<<< Date Index >>>     <<< Thread Index >>>

Re: when using `which` send errors to /dev/null



* Kyle Wheeler wrote on Thu, May 24, 2007 at 04:27:10PM CEST:
> On Thursday, May 24 at 08:24 AM, quoth Ralf Wildenhues:
>>
>>  save_IFS=$IFS
[...]
> No, that won't work, because when $IFS is expanded, it will become this:
>
>     save_IFS=

No, it will work: The shell does no word splitting after variable
expansion on parameter assignments (likewise not right after 'case').

What was missing though from my suggestion is that, if you use this
construct outside of an Autoconf-generated configure script, then you
need to ensure that IFS is initialized sometime early in the script.
POSIX allows the shell to not initialize it upon startup, in which case
it however requires word splitting to behave as if IFS contained space,
tab, newline, in that order.  But since this would break the above
assignment, it's always prudent to do the initialization explicitly.
Autoconf-generated configure scripts do this for you.  IIRC some older
release of ash or dash on RedHat at least did not have IFS set upon
startup.

Of course Vincent's remarks about $PATH_SEPARATOR is good.

Cheers,
Ralf