I'm on a Mac, and have a bash script that works very nicely. I'd like to make it so that a double-click will run it, but I don't know the "open with" operand. Please, what am I missing?
Asked
Active
Viewed 3.3k times
8
-
Welcome .. You could put your Mac related question on http://apple.stackexchange.com/ or http://superuser.com/ – fujy Sep 14 '13 at 16:43
-
2possible duplicate of [How to run a shell script in OS X by double-clicking?](http://stackoverflow.com/questions/5125907/how-to-run-a-shell-script-in-os-x-by-double-clicking) – Barmar Sep 14 '13 at 17:20
-
after making it an executable run ./your_bash_file – Dec 03 '13 at 23:59
1 Answers
41
You'll need to make the file an executable. On the first line, before any of your code put in a shebang
#!/usr/bin/env bash
REST OF YOUR CODE HERE
Next, you'll need to change the permissions. On the terminal run:
chmod +x your_bash_file
Finally, you will need to make sure OS X opens the file using the Terminal and not the application that created the file e.g. your favourite text editor. You can accomplish this in 1 of two ways:
Save the file with no file extension (eg.
bash_file
, instead ofbash_file.sh
)Or, choose
File -> Get Info
and setOpen with:
toTerminal.app
You should now be able to click on the script to execute it!

Sanketh Katta
- 5,961
- 2
- 29
- 30
-
I would probably use `chmod u+x your_bash_file`. There's no point giving `group` and `other` execute permission if it is not required – We'll See Sep 29 '22 at 10:40