snipt

Ctrl+h for KB shortcuts

Bash

Assign value of $2 to $DIR unless $2 is empty, then assign '../otherdir/' to $DIR

DIR=${2:-'../otherdir/'}
https://snipt.net/embed/60a0fabc835212ee65c624a10e2ef613/
/raw/60a0fabc835212ee65c624a10e2ef613/
60a0fabc835212ee65c624a10e2ef613
bash
Bash
1
2019-06-16T07:26:16
True
False
False
/api/public/snipt/14678/
assign-value-of-2-to-dir-unless-2-is-empty-then-assign-otherdir-to-dir
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="nv">DIR</span><span class="o">=</span><span class="si">${</span><span class="nv">2</span><span class="k">:-</span><span class="s1">&#39;../otherdir/&#39;</span><span class="si">}</span> </span></pre></div> </td></tr></table>
"default argument", "ternary operator", bash, scripting