1

If IFS is for example <tab>, then consecutive delimiters are merged by read-command. Otherwise that does not happen. Example:

$ 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

But why is this so?

  • 1
    Essentially the same question: [Read file and store as array without skipping empty strings](https://unix.stackexchange.com/a/654114) – Kusalananda Jul 17 '22 at 21:08
  • OK. So basically we can say that having mutable IFS in the first place is not a POSIX requirement. Still this does not explain why splitting by non-whitespace was not made to behave similarly. – Jori Mäntysalo Jul 18 '22 at 05:08

0 Answers0