In zsh how can I run a script which is written for bash

You can run the script with bash manually:

bash myscript.sh

A better and more permanent solution is to add a shebang line:

#!/usr/bin/env bash

Once that line is added, you can run it directly, even in ZShell:

% ./myscript.sh

As far as version control goes, you should commit this line, for the good of all the developers involved.


In addition to the solution commented by @neersighted, you should also make sure your bash script has the executive permission to run in the zsh. Thus, you should first set the first line of your bash script with shabang:

#!/usr/bin/env bash

Then run:

% chmod +x myscript.sh

to provide such permission. Then you can run it in zsh as:

% ./myscript.sh

Tags:

Bash

Zsh