Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have switched to zsh, how can I run a script which is written for bash?

I don't want to modify the script to put #!/bin/bash in the beginning for the script since it is version controlled.

Is there another way?

The line of the script having problem is:

for f in `/bin/ls v/*/ v/*/*/ d/*/*/ 2> /dev/null`
share|improve this question
This line is terrible! It's terrible bash practice to parse the output of ls. – gniourf_gniourf Dec 21 '12 at 20:56
I agree with @gniourf_gniourf. While it's a bit outside the scope of this question, you would be better off doing this: for f in v/*/ v/*/*/ d/*/*/ (this uses the built in glob-substitution of bash) – neersighted Dec 21 '12 at 23:08
up vote 9 down vote accepted

You can run the script with bash manually:


A better and more permanent solution (that should have been there in the first place) is to add a shabang line:

#!/usr/bin/env bash

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

% ./

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

share|improve this answer
Agreed -- a script that requires bash, but doesn't start with a bash shebang, should be considered broken. And broken scripts should be fixed. (Though as @gniourf_gniourf pointed out, that's not the only problem here.) – Gordon Davisson Dec 21 '12 at 22:38
As long as we are on the subject of shebangs: Why not correct to #!/usr/bin/env bash. That way the scripts work on more systems. (/usr/local/bin/bash, /usr/bin/bash etc are all hardcoded and you need to fix each script for each shell you use. With env you only have to maintain one single program). – Hennes Dec 22 '12 at 7:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .