Regarding Bourne shell and derivates, I understand IFS
to be a behavior program for field splitting (commanding how to split fields into "words") which is needed for a broader process named "parsing".
I have read that If IFS
(as an environment variable) is not set (as with unset IFS
), the shell shall behave as if the value of IFS is <space>
, <tab>
and <newline>
.
Putting the possible atrocious consequences aside for a moment, intuitively I would think that unsetting an environment variable would delete it without warnings similar to how rm -rf /*
can just destroy a system without warnings and similar to what happens with unset xyz
(as unsetting an artificially made non environment variable which is then deleted).
So, I would say that unset IFS
isn't really unsetting it but resetting it (somewhere else) into some default fallback behavior.
Is unsetting environment variables always cause some fallback behavior?
IFS
would be set to<space><tab><newline>
if unset, just the relevant functions (i.e. field/word splitting and$*
) act like it would have that value. Also,IFS
is a somewhat special case in being integral to how the shell works. Is there some reason in particular to assume that unset variable in general wouldn't be basically deleted? – ilkkachu Mar 17 '21 at 15:44just the relevant functions (i.e. field/word splitting and $*) act like it would have that value
isn't that the main functionality of IFS? – variableexpander Mar 17 '21 at 15:51Is there some reason in particular to assume that unset variable in general wouldn't be basically deleted?
Because I understood, most probably wrongly, thatunset IFS
would reset its value to<space><tab><newline>
and I wanted to understand why. – variableexpander Mar 17 '21 at 15:52If IFS is not set, the shell shall behave as if the value of IFS is <space>, <tab> and <newline>
(especially thewill behave as
) withwill reset as
orwill fallback to
. Still thiswill behave as
resembles some fallback behavior... Wouldn't you say?... – variableexpander Mar 17 '21 at 16:11