5 ways to get the most out of Bash
The Bash shell provides a powerful and flexible command line experience. Bash also supports a rich shell scripting language, with extensions to support a variety of use cases. This year, we shared some of our favorite ways to get the most out of Bash scripts. Here are our top 5 favorite articles about Bash.
Using ‘if’ in a Bash script
Automation is the key to everything. If I have a two-step process, I’m going to automate it. If it’s a multi-step process, where the next step depends on the correct execution of the one before it, you can bet I’m going to automate it. Using the if statement in Bash makes it easy to run different processes depending on whether a previous command ran successfully. Here’s one way I used if in a Bash script.
Parsing config files with Bash
Keeping program configurations separate from code is important. It enables non-programmers to alter configurations without having to modify the program’s code. Placing configuration items into easily maintained text files provides separation and lets you edit configuration elements without the danger of making unintentional changes to the code. David shows how to do this with an interpreted shell language like Bash.
How I delay code execution in Bash until a remote host is responding
In this article, David explains how he needed to reboot a remote computer and wait until it has completely rebooted and the network is up and running. Only after that occurs could a Bash script continue sending commands to that remote system. Adding a loop with sleep and ping to a Bash script makes that possible.
Using logical operators on the Bash command line
Simple compound commands—such as stringing several commands together in a sequence on the command line—are used often on the Bash command line and in Bash scripts. Such commands are separated by semicolons, which define the end of a command. All the commands will run without a problem, as long as no error occurs. But what happens if an error happens? David explains how to anticipate and allow for errors using the && and || control operators built into Bash.
How to do fast, repeatable Linux installations #1 — Bash scripts
There are many interesting and powerful tools available to automate installations. The tool you choose will depend upon the complexity of the installation and the pace of the installations being performed. However, many of those tools are too complex or expensive for smaller, sometimes simpler environments. David’s article explores how to use a Bash shell script for the relatively simple post-install needs of individuals and small organizations.
To learn more about automating a Linux install, read David’s follow-up article about Bash scripts with RPM.