shellshzshbrace-expansion

Zsh not performing brace expansion when started as sh?


Zsh isn't performing brace expansion, but only when invoked with the /bin/sh link.

$ /bin/sh --version
zsh 5.8 (x86_64-apple-darwin20.0)
$ zsh --version
zsh 5.8 (x86_64-apple-darwin20.0)
$ /bin/sh -c "echo {1..3}"
{1..3}
$ zsh -c "echo {1..3}"
1 2 3

What's going on?


Solution

  • Brace expansion is not a feature of the traditional (POSIX) shell. It is specific to bash and zsh.

    When invoked as /bin/sh, bash and zsh behave like a POSIX shell, that's why brace expansion doesn't work.