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