Shell Style Guide

Table of Contents

Background

Which Shell to Use

When to use Shell

Shell Files and Interpreter Invocation

File Extensions

SUID/SGID

Environment

STDOUT vs STDERR

Comments

File Header

Function Comments

Implementation Comments

TODO Comments

Formatting

Indentation

Line Length and Long Strings

Pipelines

Loops

Case statement

Variable expansion

Quoting

Features and Bugs

Command Substitution

Test, [ and [[

Testing Strings

Wildcard Expansion of Filenames

Eval

Pipes to While

Naming Conventions

Function Names

Variable Names

Constants and Environment Variable Names

Source Filenames

Read-only Variables

Use Local Variables

Function Location

main

Calling Commands

Checking Return Values

Builtin Commands vs. External Commands

Conclusion