Prefered language

DevOps Tools - Bash Scripting for DevOps Automation


What is Bash Shell?

GNU Bash or simply Bash is a Unix shell and command language written by Brian Fox for the GNU Project as a free software replacement for the Bourne shell. First released in 1989, it has been used widely as the default login shell for most Linux distributions and Apple's macOS Mojave and earlier versions. A version is also available for Windows 10. It is also the default user shell in Solaris 11.

Bash is a command processor that typically runs in a text window where the user types commands that cause actions. Bash can also read and execute commands from a file, called a shell script. Like all Unix shells, it supports filename globbing (wildcard matching), piping, here documents, command substitution, variables, and control structures for condition-testing and iteration. The keywords, syntax, dynamically scoped variables and other basic features of the language are all copied from sh. Other features, e.g., history, are copied from csh and ksh. Bash is a POSIX-compliant shell, but with a number of extensions.

The shell's name is an acronym for Bourne-again shell, a pun on the name of the Bourne shell that it replaces and on the common term "born again".

A security hole in Bash dating from version 1.03 (August 1989), dubbed Shellshock, was discovered in early September 2014 and quickly led to a range of attacks across the Internet. Patches to fix the bugs were made available soon after the bugs were identified. 

Bash Scripting in DevOps

The first thing any DevOps engineer learns is a scripting language to navigate through devices, software and servers. These are exceptionally powerful and are the basics of learning development. Yes, bash is certainly still used. Just have a look on a typical Linux or UNIX system for the number of shell scripts it ships with - you'll find a considerable number.

Bash is still used by most modern Linux distributions. It is often the default shell and is used for most system initialization such as the system V init scripts. It is a shell scripting language and if you are in need of maintaining a Linux server than it is a language you will need to know. If you are trying to make GUI applications it is much better to program them in a higher level language, such as python, as it will be difficult and nearly impossible to make a feature rich GUI application from a shell script. Testing GUI applications from Bash shells is very useful though so you can see any output the application may be sending to STDOUT or STDERR in real time as the application is running.

Whatever you can do with shell script, you can do with perl and python too or in general any scripting language. However These languages have advantage and disadvantage over each other.

Here are the few reasons why i use the scripts.

  • You can write a script to initialize something at boot time of the system. so you don't need to do manually.
  • You can write a script which installs per-requisite and build the code with user input to enable/disable some features.
  • To kill or start multiple applications together.
  • To observe large database of files and find some patterns out of it.
  • So in general to automate the process and the list goes on....

Additional Typical uses

  • System boot scripts (/etc/init.d)
  • System administrators, for automating many aspects of computer maintenance, user account creation etc.
  • Application package installation tools More detail
  • Application startup scripts, especially unattended applications (e.g. started from cron or at)
  • Any user needing to automate the process of setting up and running commercial applications, or their own code.

Select the language of your preference