title: What's the best way to write cross-platform shell scripts
body: <p>I have a shell script I'd like to run on multiple platforms that all support bash. My issue is that some commands behave differently on Linux, FreeBSD, OS X, and Cygwin.</p>
  
  <p>My thought so far are:</p>
  
  <ul>
  <li>Create default implementations of functions for all the OS-specific operations in the main script, then inspect <code>$OSTYPE</code> and <code>source</code> an implementation-specific file that (optionally) replaces commands that behave differently. And if I do this, how should I handle commands with several arguments? Four positional arguments passed to a function isn't the cleanest approach.</li>
  <li>Put all the implementations in my script, each with an affix in the name, inspect <code>$OSTYPE</code> and create an <code>OPSUFFIX</code> variable, then call <code>operation$OPSUFFIX</code> for each operation.</li>
  <li><code>./configure</code> magic?</li>
  <li>Migrate to something like Python&mdash;maybe the most sensible, but requires the most code changes. And if this is an idiomatic init script, this isn't an option.</li>
  </ul>