Shell Scripts


Why Shell Script?

If you find yourself running a bunch of bash commands that you would like to version control and share with others, shell script is what you are looking for.

What is a Shell Script?

Shell scripts are an executable file that contain bash commands to execute. The file extension of shell scripts are .sh and are ran by putting a ./ in front of the file name. Putting this all together in an example:

Creating a Shell Script Example

Create a file and open it in your favorite editor.


Add some bash commands to the file.

echo Hello World!
echo "Second line in bash command" 

Now before you can run the bash file, touching files does not give executable permissions by default. So we need to make it executable by changing the permissions with the chmod command.

chmod +x

Finally you can run the shell script!



About shell scripts in Terminal on Mac - Apple Docs