Where to negate logical expression in bash
<p>How do you negate a test in bash if you want to combine multiple tests?</p>

<p>The code is</p>

<pre><code>if ! [ $(pgrep Xvfb) ] || [ ! -v DISPLAY ]; then
    echo starting xvfb
    mkdir -p /tmp/xvfb
    Xvfb :1 -fbdir /tmp/xvfb &gt; /tmp/xvfb_output 2&gt;&amp;1 &amp;
    export DISPLAY=:1
fi
</code></pre>

<p>It is supposed to be sourced and to start Xvfb if not already running.
Previously, it lacked the <code>|| [ ! -v DISPLAY ]</code> part to check the existence of said variable.</p>

<p>To negate a test, you could do either <code>! [ ... ]</code> or <code>[ ! ... ]</code>, which both seem to work.</p>

<p><strong>Is the reasoning correct that you should use <code>[ ! ...]</code> because it is inside the test and thus clearer (and a bit more efficient)?</strong></p>