Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mac execute bash script

Tags:

macos

execute

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?

like image 588
user2779590 Avatar asked Sep 14 '13 16:09

user2779590


1 Answers

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 of bash_file.sh)

  • Or, choose File -> Get Info and set Open with: to Terminal.app

You should now be able to click on the script to execute it!

like image 186
Sanketh Katta Avatar answered Oct 14 '22 15:10

Sanketh Katta