As, we all know that the shell scripts are normally written and run on Linux systems but they can also be run equally well on a Mac system as on a Linux system. One can write a Shell script on Mac OS, and can run it easily, much more easily than on a Windows system. In fact, on a Mac OS, a shell script will likely run and get done what it ought to do on any Linux or Windows system, for that matter. Thus, we will see in this post, How to run shell script on Mac OS.
Lets see a sample Shell Script
In order to check this, you’ll need a Shell script that you simply can run. you’ll use one that you simply wear hand, otherwise you can use the sample script below. Open a text editor e.g., Atom or TextEdit and paste the subsequent in it. Save the file with the .sh file extension.
!/bin/bash echo "Hello World"
Run Shell Script on Mac OS
To run the Shell Script on Mac OS. Open the Terminal on Mac OS. Then, employ the cd command to maneuver to the folder that contains the shell script. The situation within the command below is simply an example. Before, doing this please, modify the command to go to whichever folder your script is really in.
Once you’re within the folder, you would like to offer the script permission to run. Use the command below but replace the instance name with the particular name of the script. The one you simply want to offer your permission to run.
chmod +w test.sh
After granting the script permission to run, use the command below to run it. Remember to modify the name of the script before you run the command.
Why shell scripts are easier to run on macOS
Shell scripts are generally easier to run on Mac OS compared to Windows because Mac OS is effectively predicated on UNIX. It is something its system has in common with a Linux system. Shell commands will run without trouble you are good to go and run with your scripts.
The example script mentioned above to check this process will simply display the text within the Terminal. But, the script you might like to run goes on to try to work something else and might be that it may need other apps/utilities installed on your Mac OS before it can run. If you’re skilled at writing shell scripts, you may be always able to modify the script you’ve got and command it to use apps or utilities that are already installed on your Mac OS.
Run Shell Script using any 3rd Party App
In Mac, it is better to have a 3rd party app if you intend to run the shell scripts often. These 3rd party apps allow one to edit the script and then run it instantly or I mean to say spontaneously. There are various shell script or text editors for Mac OS but the one I generally choose to work on is Sublime Text. Sublime Text is minimal markup script editor and supports various languages.
But for the sake of this example, let’s stick to shell scripts and see the various steps to do so :
- First and foremost, download and install Sublime Text.
- Then, open the shell script in Finder.
- And, Right-click on it and select Open With and then choose Sublime Text.
- Then, click on Tools in the top menu in the Sublime Text editor. Also, from the drop-down menu, click on Build.
- Sublime text generally asks for permissions, so, click on Allow. It then shows you the result on the bottom split screen.
Note: One is able to edit and save the various shell scripts from within the editor.
++ CONCLUSION ++ Run Shell Script on Mac
So, we now know how to run shell script on Mac OS. We have seen the various ways to do this.
Thus, through this article, you shall have an idea about the general steps involving the shell script. By and through this article, thus, I suppose I have made myself pretty clear. But, in case, you still have some doubts lingering. Then, please do write to me in the comments section and I am as always, ever-ready to help you. And, also solve your many queries and problems.
Until then bidding you Good-Bye !!! Ok, wait ….. before you go, you may check out my various other posts. Also, for the simple reason, that is, to enhance your knowledge on various other topics of importance. Also, where ??? Here……