Skip to content

Guideline for all

linux-shell-base edited this page Oct 28, 2017 · 11 revisions

Guideline for all solutions in Linux-shell-base.

General

As one core characteristic of Linux-shell-base is reusability, each solution adheres to the following rules:

  • Use a standard approach
  • Provide documentation
  • Do not contain deprecated or old-styled code
  • Include a source if exists
  • Do not depend on another solution

In adherence to the principle of simplicity, solutions also adhere to the following rules:

  • A solution cannot alter any system files.
  • A solution can output only either files and/or directories to "${HOME}/.linux-shell-base/" or files to "${HOME}/".

Code style

General

Lines and indentation
  • Spaces are used for all whitespace (tabs are allowed for Bash Here documents only).
  • An indent is 2 spaces.
Strings
  • Single quotes are used when possible.

Bash

Variables
  • An argument variable (e.g. ${1}) is used directly rather than being assigned to a new variable when possible.
  • A variable in an arithmetic expression is called without brackets (e.g. $((numEntries - count)), not $((${numEntries} - ${count}))).
Other
  • POSIX is used over extended Bash syntax (e.g. single bracket instead of double bracket conditionals) when possible.
  • A case block is used when matching 3 or more values.
  • A parameter expansion is quoted unless required otherwise.
  • A command substitution is quoted unless required otherwise.

Perl

Variables
  • A variable does not use brackets (e.g. $var, not ${var}) except when it makes sense to (e.g. in regular expressions and large scopes).
Strings
  • A variable inside a string value is simply appended to the string and the entire string is quoted with double quotes rather than using explicit concatenation.
Other
  • Parentheses are used when calling user-defined functions.
Clone this wiki locally