Difference between revisions of "DeveloperWiki:Bash Coding Style"

From ArchWiki
Jump to: navigation, search
(make it clear that this is not part of the style guide for the ArchWiki)
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
 
[[Category:Arch development]]
 
[[Category:Arch development]]
==Policy==
+
{{Note|The style on this page applies to Arch Linux software projects, not code snippets on ArchWiki articles.}}
 +
 
 +
== Policy ==
 +
 
 
* encoding is utf-8
 
* encoding is utf-8
* use ''#!/bin/bash''
+
* use {{ic|#!/bin/bash}}
 
* indent with tabs
 
* indent with tabs
 
* tabs have 8 characters
 
* tabs have 8 characters
Line 12: Line 15:
 
}
 
}
 
</pre>
 
</pre>
* if and for statements are like this:
+
* {{ic|if}} and {{ic|for}} statements are like this:
 
<pre>
 
<pre>
 
if true; then
 
if true; then
Line 26: Line 29:
 
</pre>
 
</pre>
 
* use single quotes if a string does not contain parseable content
 
* use single quotes if a string does not contain parseable content
* use ''source'' instead of ''.''
+
* use {{ic|source}} instead of {{ic|.}}
 +
* use {{ic|$()}} instead of {{ic|``}}

Latest revision as of 06:48, 9 January 2015

Note: The style on this page applies to Arch Linux software projects, not code snippets on ArchWiki articles.

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 .
  • use $() instead of ``