There is plenty of documentation available on the internet to do your own shell scripting , and more than a few scripts you can freely use or modify.
Simply letting BASH go by without a second thought is the norm for new users, but maybe with a better explanation we can change this. This is not a tutorial nor a guide so I won’t be going into things which are hard to wrap your head around (scripting). This is simply about pointing out what BASH is and why I find it very useful and powerful.
OK, let’s grab your shell and explore the history, basic usage and then go into why it may make you an efficient user. Hopefully, once you read this, you might be able to extrapolate from this article and BASH something yourself.
I guess I should start off with giving a brief history of how this BASH thing got going. Then we’ll move on what it is.
A gentleman named Stephen Bourne developed an operating system shell in 1977 which he called the Bourne Shell. (In case you were wondering it was for Bell Labs -AT&T.) Prior to that, UNIX used what was called the Thomson Shell. What both had in common besides being a shell and working on UNIX, was they used the executable command sh (which executes commands read from the standard input or from a file).
Then in 1987, another gentleman named Brian Fox, in homage to Mr. Bourne’s efforts, decided recreate the Bourne shell (which he aptly named the Bourne Again SHell). So, as it turns out BASH is actually a clever pun. Mr. Fox has since given the project to another person to maintain. The shell may seem old now, but we still use that trusty sh executable when telling the shell to do something for us.
So now that we have a brief idea of BASH’s origin, let’s move on to what exactly BASH is.
BASH is the shell, otherwise known as a command language interpreter. A free Unix shell is used by the GNU project for its operating system. It is built on top of the Linux kernel, but it can run on most Unix-like operating systems in the same fashion (which includes BSD and even Macs since they are based off of BSD).
The shell allows you to do some powerful things with very little fuss by feeding it scripts for programs to follow. Yes, the word script is what you would expect it to mean. As in a play or movie, there is a script which tells each actor what to do and when. In short, the shell will interpret what commands you want it to do.
It is important to stress the difference between scripting and programming. A script uses a sequence of commands to execute a function. Basically, a command is simply telling the machine what to do. Programming, on the other hand, involves actually writing code which will have a unified purpose (such as a word processor).
I hope I haven’t lost you yet through all of the basic history and what the heck a shell script is. If I haven’t we can move into some basic usage and how BASH can serve you.
To illustrate the idea of scripting, let’s say you want something to happen like increasing the size of your SWAP, or working with TODO list(s) or maybe even having a certain network connection stop activity to avoid bandwidth overages on your ISP bill. A common useful script is to search for a specific string within text files. When the shell interprets the command, it sends your request in a language that the machine understands and the computer is then able to do your bidding. This can be done with a terminal or included in packages or simply clicking on something. BASH is a very flexible shell.
One of the ambiguous things amongst all operating systems which I have used is the Send To command (often present in many right-click menu systems). Yes – this is actually a scripted action. It tells a program to open and do the action of sending the file. This scripting thing is taken even further past right click actions. Automation and alarms are some commands a script can be called upon to do things.
Using scripted events, the computer can install things for you with very few characters as opposed to typing each command several times. Other examples include things such as checking for updates or adjusting services during the start-up process.
In the world of Unix-like operating systems, you might have heard the word cron (which is short for chronograph). Cron allows you to run a shell script at any time you like. For example, if you want a script to run everyday at 3PM to empty your trash bin, cron is your process. Cron is a perfect example of BASH doing its thing.
As you might have noticed, there is more to BASH than meets the eye. It can range from being very simple to executing very complex actions. What can you do with BASH? Below are a few examples which I find useful:
One thing I seem to do a lot of is take and process pictures. Sure there are a few great programs to manage them, but why be tied to one program? Scripting allows you to be flexible and very light on resources. I can call on more than one program for a given action and do a variety of functions succinctly while saving resources and valuable screen working space.
Imagine if I wanted to re-size, create a folder and then move the large images there without much effort. This is where it gets fun, even darn useful with BASH, for the average user. I am not going to be using shell syntax but rather simply explain how and what you can do.
To achieve our goals we will need to call on some different actions:
- First we need to call on BASH with the script
- Next we call on ImageMagick to do the functions that we need it to (i.e. resizing the pictures or reducing image quality for file size reduction)
- Next we tell BASH to create the folder and then move pictures into the newly created folder
- Finally, we will ask that all of the programs terminate cleanly (Unix lingo for close) when everything is done
When I execute the script, I as the user am only calling on a single file, not fumbling around with all the elements as individual actions. This BASH usage allows me to avoid opening programs, dealing with pop-ups, or menus. I just accomplished my task (otherwise requiring multiple interactions), with one action.
This can be done with a ready made script or ran from the terminal. Earlier I mentioned right clicks. If you’re crafty, you can simply right click a folder and run a prepared script. (Sometimes, you may need to create or edit it to suit your needs.) This is not just limited to images alone. Video files can be done the same way (such as converting whole libraries of video from one format to another). There are plenty of other things you are able to do with BASH.
Now that we know some basics of how BASH can be fun, let’s look at the most common graphical file manager: Nautilus.
Nautilus scripting is similar to BASH scripts and I mention this because I find a lot of its scripts are ready made and simple to use for a beginner. Scripts expand the usefulness of the graphical file manager and gives some neat functions. Just make the <file>.sh executable and insert the proper structure so the shell can find it. For the most part all you have to do is make sure it has the proper permissions and in the right folder it will appear in the menu when your right click.
So we have seen some of the functions and power BASH can bring you, from running applications in batch to automation and alarms. BASH is not only a pun but also a very timeless and powerful tool for any user, even with little scripting exposure..
Tapping into it can save you a lot of time and effort. You will see installers use sh enabled installers, you can run program components or simply call on check functions. As I mentioned, this is not a guide or tutorial – I just wanted to share why I like to BASH things. With some basic understanding, you can explore options meeting your needs while bashing things yourself.