title: Chain commands until variable is not empty or undefined?
body: <p>I'm trying to populate a variable with an executable to be called later. I know the following is wrong because it's testing return values, but I'm not sure how to do it correctly (wrapped added for easy viewing):</p>
  
  <pre><code>CHECKSEC=`which checksec 2&gt;/dev/null` || `which checksec.sh 2&gt;/dev/null` || 
    `ls /usr/local/bin/checksec 2&gt;/dev/null` || `ls /usr/local/bin/checksec.sh 2&gt;/dev/null`
  </code></pre>
  
  <p>More correctly, I know I can do it with a bunch of <code>if</code> statements, but I'm trying to avoid it because it unrolls into about 4 or 8 blocks:</p>
  
  <pre><code>if [ -z "$CHECKSEC" ]; then
    CHECKSEC=`which checksec 2&gt;/dev/null`
  fi
  ...
  
  if [ -z "$CHECKSEC" ]; then
    echo "Unable to locate checksec. If you have it, be sure its on PATH. If"
    echo "  you need it, you can download it from http://www.trapkit.de/tools/."
    exit 1;
  fi
  </code></pre>
  
  <p>Is it possible to chain commands to populate a variable like I'm trying to do? (Or is this one of those "why would you do that"?)</p>
  
  <p>If so, how do I chain the commands so that [particular] processing stops when a variable is not empty and not undefined?</p>