title: Is there an inline-if with assignment (ternary conditional) in bash?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/3953645/ternary-operator-in-bash">Ternary operator (?:) in Bash</a>  </p>
  </blockquote>
  
  
  
  <p>If this were AS3 or Java, I would do the following:</p>
  
  <pre><code>fileName = dirName + "/" + (useDefault ? defaultName : customName) + ".txt";
  </code></pre>
  
  <p>But in shell, that seems needlessly complicated, requiring several lines of code, as well as quite a bit of repeated code. </p>
  
  <pre><code>if [ $useDefault ]; then
      fileName="$dirName/$defaultName.txt"
  else
      fileName="$dirName/$customName.txt"
  fi
  </code></pre>
  
  <p>You could compress that all into one line, but that sacrifices clarity immensely.</p>
  
  <p>Is there any better way of writing an inline <code>if</code> with variable assignment in shell?</p>