Dealerdirect style guide: BASH

“We must all suffer one of two things: the pain of discipline or the pain of regret or disappointment.” ~ Jim Rohn

This guide defines the BASH coding standards we use at Dealerdirect. The intent of this guide is to help developers create BASH scripts that are readable, portable easy to maintain and bug-free.

Although there are a few style guide for BASH, none of them seems to be exhaustive or detailed enough.

As a result, the Dealerdirect BASH style guide was born.

The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in RFC 2119.

Table of Content

Files

Basics

File names

File properties

BASH options

Comments / Documentation

Exit codes and Errors

Formatting

Line length

Whitespace

Lines

Declaration

Arrays

Checks

Command options

Command substitution

Functions

Function packaging

Strings

User messaging

Variables

Common pitfalls

Some more common problems and bugs in BASH can be avoided by adhering to the following conventions:

Files and folders

Internal (or “builtin”) commands

General notes

Sources

The following sources were consulted whilst making this guide:

References

^1: No newline at end of file - Mike Burns

^2: Heroku output format in BASH scripts