title: Bash: How to set a variable from argument, and with a default value
body: <p>It is pretty clear that with shell scripting this sort of thing can be accomplished in a huge number of ways (more than most programming languages) because of all the different variable expansion methods and programs like <code>test</code> and <code>[</code> and <code>[[</code>, etc. </p>
  
  <p>Right now I'm just looking for </p>
  
  <pre><code>DIR=$1 or .
  </code></pre>
  
  <p>Meaning, my DIR variable should contain either what is specified in the first arg or the current directory. </p>
  
  <p>What is the difference between this and <code>DIR=${1-.}</code>?</p>
  
  <p>I find the hyphen syntax confusing, and seek more readable syntax.</p>
  
  <p>Why can't I do this? </p>
  
  <pre><code>DIR="$1" || '.'
  </code></pre>
  
  <p>I'm guessing this means "if $1 is empty, the assignment still works (DIR becomes empty), so the invalid command '.' never gets executed."</p>