What happens if IFS is not set in shell?
If IFS is not set, the shell shall behave as if the value of IFS is . With an unset IFS, the shell shall behave as if IFS is default. That means that the ‘Field splitting’ will be exactly the same with a default IFS value, or unset.
How to reset IFS to default in Bash?
An alternative way may be to set IFS as an environment value from bash (for example) and then call sh (the versions of it that accept IFS to be set via the environment), as this: In short, sh makes resetting IFS to default quite an odd adventure.
What’s the default IFS value for Bash and zsh?
For zsh, ksh, and bash (AFAIK), IFS could be set to the default value as: IFS=$’ ‘ # works with zsh, ksh, bash. Done, you need to read nothing else. But if you need to re-set IFS for sh, it may become complex.
How to set IFS in a child script?
If there are child scripts that need IFS correctly set, you could always manually write: Where the sequence manually typed was: IFS= ‘ space tab newline ‘, sequence which has actually been correctly typed above (If you need to confirm, edit this answer).
Which is the default value for IFS in Bash?
If you want to set IFS explicitly to this default value, you can put the literal characters space, tab, newline in single quotes. In ksh93, bash or zsh, you can use IFS=$’ ‘. Portably, if you want to avoid having a literal tab character in your source file, you can use
When do you put IFS in the end of a line?
With IFS=” “, spaces at the beginning and at the end of the line are trimmed. With the default value of IFS, tabs and spaces are trimmed. Q1.
When is double quoting necessary in zsh shell?
Zsh users should skip it and read the end of When is double-quoting necessary? instead. If you want the whole nitty-gritty, read the standard or your shell’s manual. Note that the explanations below contains a few approximations (statements that are true in most conditions but can be affected by the surrounding context or by configuration).