How to make a simple bash script (Mac)
The first step to make a simple bash script is writing the script.
Open Text Edit, found in Applications, once in Text Edit, click “New Document”.
Next, write the Bash Script, as below:
#!/bin/bash tells the terminal that you are using bash shell
echo hello world prints out “hello world” in the terminal
Once you have written the script, you have to convert the document into plain text.
Select “Format” from the Menu and then click “Make Plain Text.”
Next click “File” and then “Save.”
Name it whatever you would like, but remember how you typed the name because we are going to be using that exact name in the terminal.
For the purpose of this tutorial, I am going to name it “FirstScript”, and I am going to save it in my Documents folder.
Also you have to uncheck the box that says “If no extension is provided, use ‘.txt’.”
Next you are going to open the Finder.
Search for the name of the script you just wrote, or navigate to the file.
Once you found it, right click on it (CTRL + click) and click “Get Info”.
Look on the very bottom right of the opened info window, and you will see a Lock icon that should appear locked.
Click it, and if you have a password on your computer it will ask you for your password to unlock it, otherwise it will just unlock.
Once that is done, you have to open Terminal and navigate to the folder you put the document in.
In the terminal, for my case, I am going to type in
Now we have to change the file we saved to an executable file. Type in chmod 700(file Name). I’m going to type in
chmod 700 FirstScript
This will change it into an executable file.
Now type in ./(File Name). Im going to type in
You should see “Hello World” printed out.