On Thu, Mar 30, 2023 at 10:10 AM Oğuz İsmail Uysal <oguzismailuy...@gmail.com> wrote: > > On 3/30/23 2:12 PM, Felipe Contreras wrote: > > IFS=, > > str='foo,bar,,roo,' > > printf '"%s"\n' $str > zsh is the only shell that generates an empty last field, no other shell > exhibits this behavior.
So? This is argumentum ad populum. The fact that most shells do X doesn't imply that POSIX says X. It could very well mean that all shells are implementing POSIX wrong. Except zsh. Or it could mean POSIX doesn't specify which behavior is correct. > Besides your link says: > >The shell shall treat each character of the IFS as a delimiter and use > the delimiters as *field >terminators* to split the results of parameter > expansion, command substitution, and arithmetic >expansion into fields. > > So the delimiters terminate fields, not separate them. Yes. 'foo,bar,' has two terminators, and therefore two fields. 'foo,bar,roo' has two terminators and therefore two fields, plus garbage. You want to interpret 'foo' as a field, even though it does not have an an explicit terminator. But that's not specified anywhere in POSIX. POSIX doesn't say what should be done with the text after the last terminator. You could throw it away and still be conforming to POSIX. -- Felipe Contreras