I've always wanted to be able to run a script I've downloaded online directly from the Finder but just double clicking the file does not work.
Open Terminal, type in
sh /path/to/file and press enter.
Faster is to type
sh and a space and then drag the file to the window and release the icon anywhere on the window.
Alternatively, you could also do
cd /directory/with/executable chmod +x executable # only required if your file is not already executable ./executable
which will also run the executable file with its specified shell (if specified in the shebang
chmod u+x myfile.sh cp myfile.sh /usr/local/bin
~/.bash_profile and add the following line:
execute the following command-line:
then you will be able to run your file as a program
Follow these steps to run the script files:
Right-click on the .sh file.
Hover over Open With.
You should be in the Applications folder. Open Utilities folder and select Terminal.app.
If you can't select Terminal.app, change the enabled applications from Recommended Applications to All Applications. It is at the bottom of the window.
If you want to open every
.shfile with Terminal.app, tick Always Open With.
Press the Open button in the bottom right corner of the window.
The reason it doesn't work after downloading is the file permissions don't allow it. To enable execute permissions, open Terminal and type
chmod 755 /path/to/script.
Instead of typing the full path, you can drag the script onto the Terminal window from Finder.
Then, to execute, just enter
Again, you can drag and drop the file onto the Terminal window. This syntax should execute the script using the correct shell as defined on the first line of the script.