Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

How to run a shell script on a Unix console or Mac terminal?

I know it, fail to remember it and relearn it once more. Time to record it.
by

3 Answers

ninja01
To start the shell-script 'file.sh':

sh file.sh

bash file.sh

Another option is set executable permission using chmod command:

chmod +x file.sh

Now run .sh file as follows:

./file.sh
kshitijrana14
For the bourne shell:
sh myscript.sh

For bash:
bash myscript.sh
sandhya6gczb
To run a non-executable sh script, use:

sh myscript

To run a non-executable bash script, use:

bash myscript

To start an executable (which is any file with executable permission); you just specify it by its path:

/foo/bar
/bin/bar
./bar

To make a script executable, give it the necessary permission:

chmod +x bar
./bar

When a file is executable, the kernel is responsible for figuring out how to execute it. For non-binaries, this is done by looking at the first line of the file. It should contain a hashbang:

Login / Signup to Answer the Question.