Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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/*/s.sh v/*/*/v.sh d/*/*/v.sh 2> /dev/null`
share|improve this question
3  
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/*/s.sh v/*/*/v.sh d/*/*/v.sh (this uses the built in glob-substitution of bash) –  neersighted Dec 21 '12 at 23:08

1 Answer 1

up vote 8 down vote accepted

You can run the script with bash manually:

bash myscript.sh

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:

% ./myscript.sh

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

share|improve this answer
3  
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.