title: Optionally passing arguments to commands in a script
body: <p>I've got a shell script with a section like this:</p>
  
  <pre><code>if [ "$condition" -eq 1 ]; then
      external_command -argument value1
  else
      external_command -argument value1 -second_argument value2
  fi
  </code></pre>
  
  <p>I was bugged by this repetition, so I tried this:</p>
  
  <pre><code>arg="-second_argument"
  val="value2"
  if [ "$condition" -eq 1 ]; then
      arg=""
      val=""
  fi
  external_command -argument value1 "$arg" "$val"
  </code></pre>
  
  <p>It didn't work because the <code>external_command</code> still gets the empty strings as distinct arguments and complains.</p>
  
  <p>Is there a way to do this without building the command line repeatedly? In my actual code there are 4 different conditions, so there's a lot of needless repetition.</p>
  
  <p>If I were using Bash, I'd follow <a href="http://mywiki.wooledge.org/BashFAQ/050" rel="nofollow noreferrer">Bash FAQ 050</a> and build an array for the command arguments, but I'm not.</p>