title: Bash: Create a file if it does not exist, otherwise check to see if it is writeable
body: <p>I have a bash program that will write to an output file.  This file may or may not exist, but the script must check permissions and fail early.  I can't find an elegant way to make this happen.  Here's what I have tried.</p>
  
  <pre>
  set +e
  touch $file
  set -e
  
  if [ $? -ne 0 ]; then exit;fi
  </pre>
  
  <p>I keep <code>set -e</code> on for this script so it fails if there is ever an error on any line.  Is there an easier way to do the above script?</p>