1

I'm on zsh. What is going on here...?

1

It seems I just can't set the IFS; it stays on '\n' (newline, not 'n') when I investigate, but neither in my .zshenv nor .zshrc did I set it.

Any suggestions? Thanks in advance!

EDIT

Another example of how weird my arrays are behaving: 2

Again, thanks in advance!

1 Answers1

5

The issue is not that you can't set IFS, it's that (unlike in bash for example) in zsh, unquoted variable expansions are not subject to "split + glob" (word splitting and filename generation). So the whole of $a is being assigned to the first element of b (which is $b[1], since arrays are indexed from 1 in zsh - again different from bash).

To get bash-like behavior, you can either set zsh's shwordsplit shell option, or make the variable expansion word split explicitly using $=a in place of plain $a.

For a more nuanced explanation, see What is word splitting? Why is it important in shell programming?

steeldriver
  • 81,074