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

Re: Shell Compatibility



There is a high degree of overlap among the extra-POSIX features of bash, ksh, and zsh, but the differences crop up very quickly - for instance with arrays. With some care you can write a script that works in all three shells, but if you aren't specifically trying to do that, a complex bash script is unlikely to work as-is in zsh. 

I use both bash and zsh - my interactive daily driver is zsh,  but almost anything I write for use in a system at work is bash. This is not uncommon in my experience. I do sometimes try out snippets of code intended for bash at the zsh prompt, and so have to tweak it, but the logic translates easily enough; I don't feel any need for syntax compatibility.

Mark J. Reed <markjreed@xxxxxxxxx>


On Sun, Aug 24, 2025 at 11:00 Lawrence Velázquez <larryv@xxxxxxx> wrote:
On Sun, Aug 24, 2025, at 12:48 AM, McPherran Web - Support wrote:
> Hi, friendly question/plug: Can zsh run most scripts that "bash" runs?

In sh/ksh emulation mode, it can run many scripts that bash can,
but I would consider "most scripts" to be an overstatement.

In default mode, it can only run the most drop-dead simple scripts
due to some fundamental differences in behavior.


> Is this capability as well as POSIX compatibility considered an
> important aspect of zsh?

Not really.  It's a low priority.


> (POSIX seems a bit limited, so perhaps
> inter-shell compatibility is more important in actual practice and
> usage.)

In general, zsh does not specifically aim for bash compatibility.

The sh/ksh emulation mode does accommodate some ksh features that
bash has adopted, but broadly speaking the further a script strays
from POSIX, the less likely it is that emulation can handle it
acceptably.

See the documentation for more details:

https://zsh.sourceforge.io/Doc/Release/Invocation.html#Compatibility
https://zsh.sourceforge.io/FAQ/zshfaq02.html#l10
https://zsh.sourceforge.io/FAQ/zshfaq02.html#l17


> 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 far as running scripts is concerned, I don't think this goal is
feasible or worthwhile.  There are just too many scripts out there
that require bash features/bugs (whether by design or by accident).
Even for POSIX scripts, sh emulation is good but not comprehensive.


--
vq



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