Home > OS >  bash and zsh behave differently with this command, what could be the reason for this and is there a
bash and zsh behave differently with this command, what could be the reason for this and is there a

Time:08-14

Run in bash the result is:

printf "%s\n" {a..Z}{a..Z}
bash: bad substitution: no closing "`" in `a

It works in an interesting way when run in zsh, even though zsh is usually sensitive to commands with unusual input characters.

printf "%s\n" {a..Z}{a..Z}
aa
a`
a_
a^
a]
a\
a[
aZ
`a
``
`_
`^

Is there a solution for this just under bash, so that you don't have to fiddle with zsh separately for every execution?

CodePudding user response:

what could be the reason for this

Brace expansion happens before command substitution in Bash, while it's the other way around in Zsh.

and is there a solution?

I do not think so, nothing as clean as just running zsh like zsh -c 'printf "%s\0" {a..Z}{a..Z}' | while IFS= read -d '' -r a; do echo $a; done.

  • Related