8

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?

3

1 Answer 1

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 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!

Sign up to request clarification or add additional context in comments.

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.