X
  1. Home
  2. Mac OS X
We are reader supported and may earn a commission when you buy through links on our site. Learn more

How to run a Shell or .sh script on macOS

Shell scripts are normally written and run on Linux systems but they’re almost as at home on a Mac system as they are on a Linux system. You can write a Shell script on macOS, and you can run it easily, far more easily than you can on a Windows 10 system. In fact, on macOS, a shell script will likely run and accomplish what it was written to do while on a Windows 10 system, it is far more likely to fail. Here’s how you can run a Shell or .sh script on macOS.

Test Shell script

In order to test this, you’ll need a Shell script that you can run. You can use one that you have on hand, or you can use the sample script below. Open a text editor e.g., TextEdit and paste the following in it. Save the file with the .sh file extension.

#!/bin/bash
echo "Stay Home"

Run Shell script on macOS

Open the Terminal on macOS. Use the cd command to move to the folder that the script is in. The location in the command below is just an example. Make sure you change it to whichever folder your script is actually in.

cd ~/Downloads

Once you’re in the folder, you need to give the script permission to run. Use the command below but replace the example name with the actual name of the script that you want to give permission to run to.

chmod +x test_script.sh

After granting the script permission to run, use the command below to run it. Remember to change the name of the script before you run the command.

sh test_script.sh

Why shell scripts are easier to run on macOS

Shell scripts are easier to run on macOS compared to Windows 10 because macOS is based on UNIX. It’s something the system has in common with a Linux system. Shell commands will run without trouble and you will be able to use a few select apps Linux apps too though you would benefit more from a macOS version of them if they’re available.

The example script we gave to test this process will simply display text in the Terminal but the script you want to run is going to do something else and may need other apps/utilities installed on your Mac before it can run. If you’re skilled at writing shell scripts, you can always modify the script you have and instruct it to use apps or utilities that are already installed on your Mac.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.