The Bourne-again shell is a Unix shell written for the GNU Project. Its ubiquity on Unix and Linux systems makes it a powerful tool for writing scripts to perform tedious actions (e.g. moving and modifying files).

Resource Progress Division
Bash Guide for Beginners -/12 Chapters
Advanced Bash-Scripting Guide 3/37 Chapters
GNU Bash Reference Manual -/10 Sections
IBM Bash By Example, Part 1 1/3 Parts
Learning the bash Shell 1 -/12 Chapters

Set an environment variable for a command

An environment variable can be localized to a single command if it’s declaration is prepended to the command. For example,

$ CFLAGS="-Wall" make script

passes the moifier, -Wall, to the make command.

Mimic C++ namespacing

Use :: like the scope resolution operator in C++. Although it doesn’t provide namespacing it can still be used to associate a function with a library.

Disable -x in a logging function

Bash 4.4 added support for setting options locally within a function using local -.

function log_error {
  { local -; set +x; } 2> /dev/null  # Silently disable xtrace
  # Handle logging

Additional resources

  1. Newham, Cameron and Bill Rosenblatt. Learning the bash Shell. 3rd ed. Cambridge: O’Reilly, 2005.