Bash Style Guide and Coding Standard
Source: lug.fh-swf.de
Topic: Shell Programming
Short Desciption:... of the shell and the system utilities. Occasionallytechnical journals publish articleson shell programming. ... Advanced Bash-Scripting Guide. http://www.tldp.org/LDP/abs/html/, 2006. Comprehensive tutorial ...
Content Inside:
Bash StyleGuide and Coding Standard
Bash StyleGuide and Coding Standard
With complementing comments on the testing of scripts
Fritz Mehner
Fachhochschule
Südwestfalen, Iserlohn
mehner@fh-swf.de
Contents
1
Length of line
2
2
Indentation
2
3
Comments
2
3.1 Introductory comments in files. 2
3.2 Lineendcomments. 2
3.3 Sectioncomments. 2
3.4 Functioncomments. 3
3.5 Commenting style. 3
4
Variables and constants
3
4.1 Useofvariables. 3
4.2 Useofconstants. 4
5
Success verification
4
5.1 Commandline options. 4
5.2 Variables, commands and functions 4
5.3 Execution and summary reports. 5
6
Files
5
7
Command line options
6
8
Use of ShellBuiltin Commands
6
9
SUID/SGID-Scripts
7
10 Testing
7
10.1 Syntaxcheck. 7
10.2 Testscope. 8
10.3 Useof echo . 8
10.4 Testingusing bash options. 8
10.5 Testingbymeansof trap . 9
10.6 Thedebugger bashdb . 10
11 Furthersources of information
10
12 Summary
11
Often, script programming is considered to generate only rapid and hardly to understand"throwaway
solutions"which do not have to meet any specific quality requirements. However it is often
ignored that there are many areas where long-living scripts are quite the rule: System management,
start and configuration of operating systems, software installations, automation of user tasks and so
on. And, of course, these solutions need to be maintained, extended and documented.
When it comes to script programming therefore the same requirements have to be fulfilled than when
programming inaproduction language (meeting the purpose, correctness of the solution, meeting the
requirements, robustness, maintainability) and therefore the same standards have to be employed. A
program can only be maintained, if its structure and effect can be understood easily by someone who
has not written the program, so that successful changes can be executed in reasonable time. The way
...

