title: Bash coding conventions
body: <p>I am trying to learn some Bash to maybe get a job working with computers one day.</p>
  
  <p>To improve my clarity and disciple writing my self-learning code, I am trying to adhere to a set of consistent "guiding principles".</p>
  
  <p>As I roll my own "guidelines" I obviously ask myself: should I not be using an established standard instead?</p>
  
  <p>I could not find one such "authoritative" reference for Bash, similar to what these other languages have:</p>
  
  <ul>
  <li>Java (<a href="http://www.oracle.com/technetwork/java/javase/documentation/index-137868.html">http://www.oracle.com/technetwork/java/javase/documentation/index-137868.html</a>)
  How to Write Doc Comments for the Javadoc Tool</li>
  <li>Java (<a href="http://www.oracle.com/technetwork/java/javase/documentation/codeconvtoc-136057.html">http://www.oracle.com/technetwork/java/javase/documentation/codeconvtoc-136057.html</a>) Code Conventions for the Java Programming Language</li>
  <li>Java (<a href="https://code.google.com/p/java-coding-standards/wiki/Introduction">https://code.google.com/p/java-coding-standards/wiki/Introduction</a>) Google Java coding standards</li>
  <li>Python (<a href="http://www.python.org/dev/peps/pep-0008/">http://www.python.org/dev/peps/pep-0008/</a>) PEP 8 -- Style Guide for Python Code</li>
  <li>Python (<a href="http://google-styleguide.googlecode.com/svn/trunk/pyguide.html">http://google-styleguide.googlecode.com/svn/trunk/pyguide.html</a>) Google Python Style Guide</li>
  </ul>
  
  <h3>Is there a link with a similar document for Bash which has good reason for being used?</h3>
  
  <p>Here is the type of stuff I was putting together on my own... but I think, especially as a beginner, I should be using guidelines written by experts rather than trying to come up with my own, as they would not be based on much experience, insight, practicality, knowledge of common patterns/anti-patterns, etc.</p>
  
  <p>You may dispute the validity of such documents in general, but <em>some</em> people must like them for the web to have such prominent examples online as the ones I mention in the bullet-list above..</p>
  
  <hr>
  
  <pre><code>################################################################################    
  # Coding conventions                                                                
  #                                                                                   
  # - Prefer lines of 80 characters of length or less                                 
  #                                                                                   
  # - Perform arithmetic operations and numeric comparisons within "(( ))" blocks     
  #   e.g. if ((42&lt;=24+24)), ((3**3==27))                                             
  #                                                                                   
  # - Reference variables by name, not expansion, within arithmetic evaluation        
  #   e.g. ((i++)) rather than (($i++)), ((v+=42)) rathern than v=$(($v+42))          
  #                                                                                   
  # - Prefer "[[" to "[" for conditional expressions                                  
  #                                                                                   
  # - Prefer "[[ $s ]]" to "[[ -n $s ]]" when checking for empty strings              
  #                                                                                   
  # - Document each function with at least a summary sentence. This should not        
  #   exceed the preferred line length, be written in third person, end with a        
  #   period and concisely describe the general utility of the function   
  #
  # ...
  # ...
  # ...
  #            
  ################################################################################    
  </code></pre>
  
  <hr>