Jay Taylor's notesback to listing index
Shell Style Guide[web search]
Shell Style Guide
Revision 1.26Paul Armstrong
Too many more to mention
Each style point has a summary for which additional information is available by toggling the accompanying arrow button that looks this way:. You may toggle all summaries with the big arrow button:
Bashis the only shell scripting language permitted for executables.
Shell Files and Interpreter Invocation
.shextension. Libraries must have a
.shextension and should not be executable.
While you should follow the style that's already there for files that you're modifying, the following are required for any new code.
; thenon the same line as the
- Indent alternatives by 2 spaces.
A one-line alternative needs a space after the close parenthesis of
the pattern and before the
Long or multi-command alternatives should be split over multiple
lines with the pattern, actions, and
;;on separate lines.
- Always quote strings containing variables, command substitutions, spaces or shell meta characters, unless careful unquoted expansion is required.
- Prefer quoting strings that are "words" (as opposed to command options or path names).
- Never quote literal integers.
- Be aware of the quoting rules for pattern matches in [[.
- Use "$@" unless you have a specific reason to use $*.
Features and Bugs
$(command)instead of backticks.
[[ ... ]]is preferred over
evalshould be avoided.
::. Parentheses are required after the function name. The keyword
functionis optional, but must be used consistently throughout a project.
declare -rto ensure they're read only.
local. Declaration and assignment should be on different lines.
mainis required for scripts long enough to contain at least one other function.
Use common sense and BE CONSISTENT.
Please take a few minutes to read the Parting Words section at the bottom of the C++ Guide.