How to Run Shell Script on macOS

MD Aminul Islam Feb 02, 2024
  1. Run the Shell Script on macOS
  2. Run the Shell Script on Unix or Linux
How to Run Shell Script on macOS

We can run the Bash script not only on the terminal of Linux but also on the terminal of Unix and macOS. Running a Bash script on Unix and macOS is not hard.

It’s just a matter of a few lines of command. This article will show how we can run a shell script on Unix and macOS environments.

We will discuss the topic step by step to make it easier to understand.

Run the Shell Script on macOS

We must take a few easy steps to run the shell script on macOS. Let’s discuss them part by part.

First, we need to open the terminal on macOS, and then we need to go to the exact directory where the file is. To do this, you must use the below command.

cd ~/YOUR_DIRECTORY

Now when you are in the directory, you need to provide permission to the script. To do this, you need to use the below command.

chmod +x TextScript.sh

Please note that without providing the necessary permissions, the script will not run. After providing the necessary permissions, you can run the script with the below command.

sh TextScript.sh

Run the Shell Script on Unix or Linux

To run the shell script on Unix or Linux environment, you first need to run the terminal on Linux or Unix. After that, you need to provide permission to the script by using the command shared below.

chmod +x TextScript.sh

After providing all the necessary permissions, you can run the script using the below command.

./TextScript.sh

Or

sh TextScript.sh

Remember providing necessary permissions is very important. Without this, you cannot run the script.

MD Aminul Islam avatar MD Aminul Islam avatar

Aminul Is an Expert Technical Writer and Full-Stack Developer. He has hands-on working experience on numerous Developer Platforms and SAAS startups. He is highly skilled in numerous Programming languages and Frameworks. He can write professional technical articles like Reviews, Programming, Documentation, SOP, User manual, Whitepaper, etc.

LinkedIn