O exemplo não define IFS
dentro do script, porque o bash não permite importar IFS
do ambiente, de acordo com um comentário em variables.c
:
/* Don't allow IFS to be imported from the environment. */
temp_var = bind_variable ("IFS", " \t\n", 0);
setifs (temp_var);
Comandos incorporados e não script usam a atribuição para IFS
, é claro, mas lembre-se de que IFS
só se aplica a word-splitting :
The shell treats each character of
$IFS
as a delimiter, and splits the results of the other expansions into words using these characters as field terminators. IfIFS
is unset, or its value is exactly<space><tab><newline>
, the default, then sequences of<space>
,<tab>
, and<newline>
at the beginning and end of the results of the previous expansions are ignored, and any sequence ofIFS
characters not at the beginning or end serves to delimit words. IfIFS
has a value other than the default, then sequences of the whitespace characters space and tab are ignored at the beginning and end of the word, as long as the whitespace character is in the value ofIFS
(anIFS
whitespace character). Any character inIFS
that is not IFS whitespace, along with any adjacentIFS
whitespace characters, delimits a field. A sequence ofIFS
whitespace characters is also treated as a delimiter. If the value ofIFS
is null, no word splitting occurs.