Add style guide items for case label globbing and [[ ]] vs [ ].

This commit is contained in:
Ville Skyttä 2009-11-20 22:54:44 +02:00
parent 2a506ec3f7
commit 08c51bccbd

View File

@ -11,17 +11,29 @@ Indentation
-----------
Indent step should be 4 spaces, no tabs.
Globbing in case labels
-----------------------
Avoid "fancy" globbing in case labels, just use traditional style when
possible. For example, do "--foo|--bar)" instead of "--@(foo|bar))".
Rationale: the former is easier to read, often easier to grep, and
doesn't confuse editors as bad as the latter, and is concise enough.
[[ ]] vs [ ]
------------
Use [[ ]] instead of [ ] when testing multiple conditions. [ ] is fine
for single conditions where the syntax works. Rationale: [[ ]] has
short circuit behavior within one test containing multiple conditions
separated by && or ||, while [ ] with -a or -o does not. Thus it can
be more efficient in some cases and may reduce need for nesting
conditions, and it's cleaner to write for example [[ ... && ... ]]
than [ ... ] && [ ... ], and in general [[ ]] has more features.
/////////////////////////////////////////
case/esac vs if
---------------
simple matching vs extended globbing
------------------------------------
in case statements: -@(a|b)) vs -a|-b)
testing with [[ ]] vs [ ]
-------------------------
line wrapping
-------------