Skip to content

Guideline for one_liners

linux-shell-base edited this page Oct 21, 2017 · 16 revisions

Guideline for one-liners in Linux-shell-base.

  1. General
  2. Format
  3. Code style

General

A one-liner ...

  • has a description.
  • is continued on a single line (for easy maintenance of layout when copying and pasting to a script or terminal).

Format

One-liner files are created in the following format:
(Note: Any section in addition to Description is included if necessary)

# Description
one-liner

# Description
one-liner

# Description
# Note: Note
one-liner
  • Any other documentation section is included if necessary.

For an example, see one-liners-output.bash.

Code style

General

Lines and indentation
  • Spaces are used for all whitspace.
Variables
  • A variable name uses acronyms whenever possible.
Strings
  • Single quotes are used when possible.

Bash

Variables
  • A non-global variable inside a function is declared local.
  • A variable in an arithmetic expression is called without brackets (e.g. $((numEntries - count)), not $((${numEntries} - ${count}))).
  • An argument variable (e.g. ${1}) is used directly rather than being assigned to a new variable when possible.
Conditionals
  • A single bracket conditional is used when possible.
Other
  • A parameter expansion or command substitution is quoted unless otherwise required.

All other code style rules are up to the contributor. They are reviewed however.

Clone this wiki locally