Shell Coding Style
- Indent with tabs
Opening braces are top right, closing braces are bottom left. Example:
foo() { echo bar }ifandforstatements like this:if true; then do something else do something else fi for i in a b c; do echo $i doneUse single quotes unless the string contains parseable content, e.g.;
foo='bar baz boo' foo="$bar $baz $boo"What about:
`` vs $(); source vs .; $foo vs ${foo} ?sourceis a bashism. ‘.’ is sh, but it’s easier to grep forsource. Usesourcewhen the script is bash and you’re pretty sure it will stay bash, ‘.’ otherwise.${foo}should only be used when it’s needed.
from the arch-dev-public mailing list and subsequently http://wiki.archlinux.org/index.php/DeveloperWiki:Bash_Coding_Style