例如,如果 IFS 为<tab>
,则连续的分隔符将通过读取命令合并。否则就不会发生这种情况。例子:
$ echo -e 'zero\tone\ttwo\tthree' | while IFS=$'\t' read -a x; do echo "${x[2]}"; done
two
$ echo -e 'zero\t\tone\ttwo\tthree' | while IFS=$'\t' read -a x; do echo "${x[2]}"; done
two
$ echo -e 'zero§one§two§three' | while IFS=§ read -a x; do echo "${x[2]}"; done
two
$ echo -e 'zero§§one§two§three' | while IFS=§ read -a x; do echo "${x[2]}"; done
one
但为什么会这样呢?