I see following code in a script:
OLD_IFS="$IFS"
IFS='something-special'
# code that needs the special IFS
# ...
IFS="$OLD_IFS"
If the IFS
is not set before the script fragment then the script sets it to an empty string and the empty IFS
and undefined IFS
are different.
The script probably assume the IFS
is always set. Is it safe to make such assumption?
IFS
may possibly not be inherited from the parent environment, in which case it will be set to space-tab-newline. If is inherited, it may obviously have another value. – Kusalananda May 21 '18 at 06:55