Why every Pantheon user should learn Bash - Part 2: What is Bash?

In part 1 of this series, I talked about why you would want to embrace Bash and encouraged everyone to not fear it. I firmly believe that the best way to conquer fear is with information. In that spirit, we will next dig into what Bash even is, how it does what it does, and a little bit of history.

Sending text messages to your computer

Let’s imagine you are planning a party on short notice. You want friend A to bring chips and friend B to bring dip. You could write formal letters by hand and mail them, but using your phone to text your friends would be a much faster and more reasonable way to communicate your needs and get a response.  

Chips and 3 kinds of dip

At its heart, Bash’s goal is to let the user write text messages directly to the operating system.  These messages tell the computer to do a thing. That’s it.

This means we have a direct way to interact with the text files on a machine. When I say ‘text files’ here, what I mean are much more than the ones ending in‘.txt’. Every program is also stored in text files, just with extensions like, ‘.c’, ‘.php’, ‘.js’, ‘.html’ and very importantly, as we will see in the 4th part of the series, ‘.sh’.  Bash gives you a way to create, delete, copy, move, and even execute the files.

How we create these texts can be as simple as a few keystrokes or as elaborate as using Amazon’s Alexa. Really. Alexa fundamentally works by interpreting your words into little text messages to send over the internet and reads you the little text messages that it gets back.  Nothing too scary about text messaging, right? Learning Bash should be no more frightening.

A sort of glue

Let’s get back to our party for a minute. There are many kinds of chips and dips in the world and you realize that if friend B knew what chips friend A was bringing, it would likely make for a better pairing. Now you could have friend A text you back and then communicate that with friend B. It is pretty clear though that it would be more efficient just to have friend A text friend B what chips they end up buying.  

One of the main reasons Bash became ubiquitous, is it allows output from one command to be fed into the input of another. This changed the very nature of how tools could interact. In other words, Bash can be used as an all-purpose glue between all the other programs.  

Let’s look at a simple example of this. If I wanted to make a copy of the names of all of my files and folders in my Download folder and store them in a file called “downloadedfiles.txt,”  I could:

  1. Open up the Download folder

  2. Highlight all the files

  3. Copy all the files

  4. Open up a text editor

  5. Paste into that document

  6. Save the file with a name “downloadedfiles.txt”.

Alternatively, I could:

  1. Open my terminal

  2. Run the command ‘ls ~/Downloads > downloadedfiles.txt’ (Print the directory listing of Downloads directly to the file, creating it if it does not exist.)

If I can save some steps, why would I not do that?

You can use Bash to tie together any tool that offers an API or CLI. This gives us a universal language for computer science. This glue lets us do things like automated testing with Behat, BackstopJS, AXE, and Lighthouse on every single update, like we do with our Terminus Auto Update Script.  

Tying together any open source tools is literally the heart of what computer science can give us, standing on the shoulders of giants and inventing new tools along the way that we can share to make a better world.  

So why do we call it Bash?

Bash is actually an acronym for the Bourne Again SHell (BASH), named for Stephen Bourne who invented the Bourne Shell for Bell Lab's Unix in 1979. In 1988 Richard Stallman and Brian Fox rewrote Bourne’s Shell for use with GNU and other Free and Open Source Software. The reason you and I use Bash though is because Linux adopted Bash as its shell.

Getting back to our party analogy, we are in fact throwing a party called the Open Web and you are all invited. We speak the language of Bash to coordinate our tools more effectively. And those of us who speak it are very happy to help you learn it.

Hopefully you are now a little less anxious about diving into Bash. In the next section, we will roll up our sleeves and dig into the commands themselves to take you from staring at an intimidating command prompt to mastering the basics of the built-in commands and how to not have to type as much as you think you might.  

Topics Development, Drupal, Website Technology, WordPress

Let’s get in touch