Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Shell Compatibility



On 2025-08-24 at 00:48 -0400, McPherran Web - Support wrote:
> Hi, friendly question/plug: Can zsh run most scripts that "bash" runs?
> Is this capability as well as POSIX compatibility considered an
> important aspect of zsh? (POSIX seems a bit limited, so perhaps
> inter-shell compatibility is more important in actual practice and
> usage.) As I say, it's a "plug" as well as a question so the "plug" is
> that in general I'd like to be able to use zsh in place of "bash" as
> much as possible. :-)

As someone who has added some of the bash-compatible features: if
there's something which makes life easier for folks and doesn't add much
complexity or risk breaking existing functionality, the project is open
to patches.  Nobody is rushing to audit and sweep for 100%
compatibility, but as things are found which are beneficial, those can
be added (but not via code copying, since Zsh is BSD licensed and bash
is GPL).

Quite a few features actually come from ksh, and we have copied those,
picking up Bash compatibility for free.

I added flags to some pre-command modifiers because some fleet-wide
remote-exec systems at my then employer assumed `exec` took flags; Zsh
already had all the functionality in other ways, but letting Zsh take
the flags and do the same things meant that people could safely set Zsh
as their login shell without breaking things.  Small change, easy win.

The Perl =~ operator was copied by Bash for conditional expressions; Zsh
had long had `-pcre-match` and I added `=~` as an alias for it, and then
wrote zsh/regex because maintainer consensus was that in this case, it
was better for the default behavior to more closely match Bash than
Perl.  (If doing it again, I would use an internal magic variable
instead of a setopt to change the engine behind `=~`, to make it easier
to add re2 support).

More recently, others have copied things such as the Ksh
`:offset:length` subscripting, as used in bash, which improves
compatibility (but I don't think that's yet been in a release of Zsh?).

So you can't assume bash compatibility, but if you need it and write it,
then it has a fair chance of getting accepted.  It won't be rejected on
a Not Invented Here basis.

-Phil




Messages sorted by: Reverse Date, Date, Thread, Author