How to Make a Bash Script Executable on a Mac

  Matt Cone       January 9, 2021      Tutorials Mac Developer


Bash scripts are files containing code that tell your computer to do something. They’re a staple of the Linux world, and there are thousands of them freely available on the internet. With a bit of tweaking, you can use these scripts on your Mac, too. In this tutorial, you’ll learn how to make a bash script executable on a Mac.

Here’s how to make a bash script executable on a Mac:

  1. Add the following line to the very top of your bash script, before any of the code:

    #!/usr/bin/env bash
    
  2. Make the script executable by changing the file permissions. Run the following command using a Terminal application:

    chmod +x your-script
    

Depending on how you created the bash script, you might need to change the default application that opens it. Select the file in the Finder, and then select Get Info from the File menu. In the Open with section, make sure there’s a Terminal application selected, as shown below.

Make a bash script executable on a Mac

Running a Bash Script on a Mac

Now you can run your bash script! To start it, simply double click it in the Finder. Or, in a Terminal application, run the following command:

./your-script

That’s all there is to it!

Subscribe to our email newsletter

Sign up and get Macinstruct's tutorials delivered to your inbox. No spam, promise!


About    Privacy Policy    Terms and Conditions

© 2023. A Matt Cone project. CC BY-NC-SA 4.0. Made with 🌶️ in New Mexico.