Please enable JavaScript eh!

 ⌘ Web Mechanic ⌘ 

Bash Scripting


Why Scripting?



Computers don't do what you want
They do what you tell them do do

To clear up some confusion you might have, let's get a definition of what scripting is in this environment.

All scripts (or programs) begin with source code, which are commands written in a text file to perform various operations. To run or execute the commands, we can now simply refer to the file we put them in, instead of entering them individually.

So scripting generally is programming, but on a slightly smaller scale. Instead of writing thousands of lines of code (perhaps as part of a team) in C or Pascal or Swift, we are going to use the commands available to us in the bash shell. These are usually smaller projects, but can still be quite complex and useful.


If you've spent some time working with CLI in Terminal, you may have asked 'What's the advantage to scripting?'.

Here's a few good reasons why you might consider it:

Use CLI for those quick one-off jobs, ad-hoc queries, or troubleshooting

Use a script for repetitive or complex jobs, or monitoring.

With that said, we will begin with explaining what scripting means, as far as I understand it.

Scripting or programming is writing code (typing commands and text) to do specific things - telling the computer what you want it to do.

Since we're talking bash here, the commands are usually built-in commands or executable commands available to bash. Those are what we will be using.

It generally means saving those commands in a file, then executing that file to do the job, rather than entering the commands on the Command Line in a shell.

A good understanding of the commands available to you is essential - how do you ask for a coffee if you don't know the language?

If you've gone through the links up to here, you should be ready for some real work.

User Input