-
Notifications
You must be signed in to change notification settings - Fork 6
Bash Shell Scripting CodingStyle
Techlive Zheng edited this page Jan 5, 2014
·
3 revisions
Shell scripting is very flexible, some basic coding standards should be followed.
-
Variable naming convention
Environmental variable name should be in upper case, any other variable name should all be in lower case. Global variable name should be prefixed with
__
(eg,$__file
), but local variable name should not have any prefix. -
Function naming convention
Function name should be prefixed with
_
(eg,_current_path
) in lower case. -
Using
$(..)
instead of\
..`` for command substitution -
Double quote any command parameter
-
Keep if statement as follow
if ... then ... elif ... then ... else ... fi
Do not write
if
andthen
in the same line -
Use extended test
[[]]
instead of[]
as much as possible -
Use
OPT_*
for internal option holder