Difference between revisions of "DeveloperWiki:Bash Coding Style"

From ArchWiki
Jump to: navigation, search
(5 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 +
[[Category:Arch development]]
 
==Policy==
 
==Policy==
 
* encoding is utf-8
 
* encoding is utf-8
Line 4: Line 5:
 
* indent with tabs
 
* indent with tabs
 
* tabs have 8 characters
 
* tabs have 8 characters
* don't use more than 132 columns
+
* do not use more than 132 columns
 
* opening braces are top right, closing are bottom left:
 
* opening braces are top right, closing are bottom left:
 
<pre>
 
<pre>
Line 24: Line 25:
 
done
 
done
 
</pre>
 
</pre>
* use single quotes if a string does not parseable content
+
* use single quotes if a string does not contain parseable content
 
* use ''source'' instead of ''.''
 
* use ''source'' instead of ''.''
==Modelines==
 
Add these lines at the bottom of the document to enforce our guideline:
 
* Kate (and other KDE editors): http://kate-editor.org/article/katepart_modelines
 
<pre>
 
# kate: encoding utf-8; eol unix; hl Bash
 
# kate: indent-mode normal; indent-width 8; tab-indents on; tab-width 8; word-wrap on; word-wrap-column 132
 
</pre>
 

Revision as of 10:57, 23 April 2012

Policy

  • encoding is utf-8
  • use #!/bin/bash
  • indent with tabs
  • tabs have 8 characters
  • do not use more than 132 columns
  • opening braces are top right, closing are bottom left:
foo() {
        echo bar
}
  • if and for statements are like this:
if true; then
        do something
else
        do something else
fi
for i in a b c; do
        echo $i
done
  • use single quotes if a string does not contain parseable content
  • use source instead of .