unexpected IFS behavior with the newline character
Can anybody explain this shell behavior? -- It doesn't seem consistent
with the documentation about how whitespace is interpreted as an
internal field separator.
# IFS="\n"
# FOO="alpha\nbravo\ncharlie"
# for i in $FOO; do echo "%${i}%"; done
%alpha%
%%
%bravo%
%%
%charlie%
When ash or bash does the word splitting, a empty field is expanded.
This behavior seems to happen only with the newline character.
# IFS="\n"
# FOO="alpha\n\n\nbravo\n\ncharlie"
# for i in $FOO; do echo "%${i}%"; done
%alpha%
%%
%%
%%
%%
%%
%bravo%
%%
%%
%%
%charlie%
In this case, the newline characters are not folded together like
whitespace. Generally, there are '2n-1' null expansions for each 'n'
instances of the newline character in the input word.
TIA.
Reply to: