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

Re: help adapting bashism for zsh



On Sun, Jun 9, 2019 at 5:34 PM David C. Rankin
<drankinatty@xxxxxxxxxxxxxxxxxx> wrote:
>
> Is there any collection of aliases, tweaks, brute-force sed scripts, etc..
> that I could look at an pull parts from to handle most of the issues?

First thing -- how are these scripts executed?  E.g., are they run as
standalone processes via interpreter named in a "#!" line at the top,
or are they somehow pulled into an interactive shell, or something
else?

If using the "#!" interpreter, the first thing to try is simply to
symlink that name to your zsh binary.  When invoked as (a path ending
in) "bash" or "sh" (or "ksh"), zsh enters a compatibility mode that
will resolve the most common issues.  You can then work on specific
problems with any scripts that are still failing.

This compatibility mode differs from setting individual options such
as KSH_ARRAYS, but can be fairly closely duplicated by using the
"emulate" command.  If the scripts are intended to become the bodies
of shell functions, try adding "emulate -L sh" at the top.

> Then what to do about the non-existing expansions such
> as ${foo^^} (uppercase) and ${foo,,} (lowercase), etc..

These are handled with (in those specific examples) ${foo:u} and
${foo:l}.  In fact ^^ has a completely different meaning in zsh, so
you will have to do a search-and-replace for those kinds of
nonstandard tricks.



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