Programming Bash #1 – Introducing a New Series

0

Last Updated on December 29, 2023 by David Both

I use Bash all the time, in part because it is the default shell for most Linux distributions, including Fedora and CentOS, the ones I normally use. However I also use Bash because it is an excellent shell and it has a large number of features to make life easier for the Lazy SysAdmin.

Features like tab completion, command line recall and editing, shortcuts like aliases, and more all contribute to its value as a powerful shell. One of my favorite Bash features is that, although it uses Emacs mode for command line editing by default, that can be changed to Vi mode so that I can use editing commands that are already part of my muscle memory.

But if we think of Bash solely as a shell we miss much of its true power. While researching Bash for my three-volume Linux self-study course1, upon which this series of articles is based. I learned things about Bash that I never knew in over 20 years of working with Linux. Some of these new bits of knowledge relate to its use as a programming language. Bash is a powerful programming language, one perfectly designed for use on the command line and in shell scripts. For this series we are exploring its use on the command line interface (CLI).

Let’s start with a few basics.

What is a shell?

A shell is the command interpreter for for the operating system. Each of the many shells available for Linux interprets the commands typed by the user or SysAdmin into a form usable by the operating system. When the results are returned to the shell program, it displays them on the terminal. All of the shells with which I am familiar are also programming languages.

Bash stands for Bourne Again Shell because the Bash shell is based upon the older Bourne shell which was written by Steven Bourne in 1977. Many other shells are available.2 The four I list here are the ones I encounter most frequently but many others exist.

  • csh – the C shell for programmers who like the syntax of the C language.
  • ksh – the Korn shell, written by David Korn and popular with Unix users.
  • tcsh – a version of csh with more ease of use features.
  • zsh – which combines many features of other popular shells.

All shells have some built-in commands that supplement or replace the commands provided by the core utilities. Open the man page for Bash and find the “BUILT-INS” section to see the list of commands provided by the shell itself.

I have used the C shell, the Korn shell and the Z shell. I still like the Bash shell more than any of the others I have tried. Each shell has its own personality and syntax. Some will work better for you and others not so well. Use the one that works best for you, but that might require that you at least try some of the others. You can change shells quite easily.

All of these shells are programming languages as well as a command interpreter.

About this Series

There are seven additional articles in this series. Each of the first four articles introduces you to an aspect of Bash such as its use on the command line, using loops and logical operations. The final four articles will introduce you to programming with Bash, both from the command line as well as the use of Bash programs which are also known as scripts.


Series Articles

This list contains links to all eight articles in this series about Bash.

  1. Programming Bash #1 – Introducing a New Series
  2. Programming Bash #2: Getting Started
  3. Programming Bash #3: Logical Operators
  4. Programming Bash #4: Using Loops
  5. Programming Bash #5: Automation with Scripts
  6. Programming Bash #6: Creating a template
  7. Programming Bash #7: Bash Program Needs Help
  8. Programming Bash #8: Initialization and sanity testing