Bourne to Bourne Again Shell Forward Compatibility

Bourne Again Shell

Stemming from the effort of the „GNU’s Not UNIX“ project to provide an alternative toolchain, compatible to, while improving on basic UNIX utilities, a shell interpreter called „Bourne Again SHell“, short „GNU Bash“, even shorter „Bash“ was developed by Brian Fox and others.

Bash is the default shell on many variants of Linux, contributing to the „GNU/Linux“ moniker.

The typical shebang-headline for a shell script that is specifically written for Bash is:

#!/bin/bash

Bourne Again Shell will most likely be available as executable /bin/bash if the target system for running the script is a GNU/Linux in regular service operation (meaning, not in a rescue system or initramfs). A notable exception are container environments, where Bash (or any shell executable for that matter) could have been omitted to save space or reduce complexity.

On systems where Bash is available but optional, for example FreeBSD, a Shebang line as follows could be used:

#!/usr/bin/env bash
...

Running this script as an executable will determine if an executable bash is in PATH and execute the script with it; otherwise it will exit with a return code of 127 and a „no such file or directory“ error message.

Bash, like the variants and derivatives previously described,  remains a degree of backwards-compatibility to Bourne Shell, and many Bourne or POSIX Shell scripts execute in Bourne Again Shell without errors. The following sections list some problems.

Imprint RSS