2

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?

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
YOLT
  • 133
  • 2
  • 6
  • Same root cause as [brace expansion not working on Dockerfile run command](https://stackoverflow.com/questions/40164660/bash-brace-expansion-not-working-on-dockerfile-run-command), or [brace expansion not working in system() function](https://stackoverflow.com/questions/47509608/brace-expansion-in-c-program-with-system-function); it doesn't matter who provides your `sh`, it's still responsible for complying with the POSIX sh standard, and brace expansion is not part of that standard. – Charles Duffy Jan 07 '21 at 01:45
  • @YOLT : Invoke it directly via `zsh`, not via `sh`. AFIK, zsh - like bash - has a look at how it is invoked, and behaves differently depending on what it finds in `$0`. – user1934428 Jan 07 '21 at 08:01
  • 1
    For details about what `zsh` disables when invoked as `sh`, see http://zsh.sourceforge.net/Doc/Release/Invocation.html#Compatibility – Shawn Jan 07 '21 at 09:08
  • 1
    Why is `/bin/sh` a link to `zsh`? That's certainly not the case prior to Big Sur (and I would be very surprised if that became the default in Big Sur). – chepner Jan 07 '21 at 14:03

1 Answers1

5

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.

xhienne
  • 5,738
  • 1
  • 15
  • 34