title: sh conditionally pass an option to command
body: <p>I want to do something like:</p>
  
  <pre><code>#!/bin/sh
  
  [ -f "/tmp/nodes" ]
  [[ $? -eq 0 ]] &amp;&amp; VAL=$? ||
  
  geth --datadir /root/.ethereum \
       ${VAL+"--nodekey \"/root/nodekey.txt\""} \     
       --networkid 1999 \
       --rpc \
       --rpcaddr "0.0.0.0" \
  </code></pre>
  
  <p>I want the option <code>--nodekey "/root/nodekey.txt"</code> to be passed if the file <code>/tmp/nodes</code> exists. How can that be done more elegantly than an <code>if</code> with two nearly identical commands?</p>
  
  <p>--EDIT--</p>
  
  <p>This is the best I've been able to get working so far:</p>
  
  <pre><code>if [ $VAL -eq 0 ]; then
      /geth --datadir /root/.ethereum \
            --nodekey "/root/nodekey.txt" \
            # No dice
            # Would be nice if this worked so I didn't need the if
            # ${VAL+ --nodekey "/root/nodekey.txt" } \
            --networkid 1999 \
            --rpc \
            --rpcaddr "0.0.0.0" 
  else
      /geth --datadir /root/.ethereum \
            --networkid 1999 \
            --rpc \
            --rpcaddr "0.0.0.0" \
  fi
  </code></pre>
  
  <p>This is another line in the file and works fine:</p>
  
  <pre><code>ENODE_URL=$(/geth --datadir /root/.ethereum ${VAL+ --nodekey "/root/nodekey.txt"} --exec "${JS}" console 2&gt;/dev/null | sed -e 's/^"\(.*\)"$/\1/')
  </code></pre>