snipt

Ctrl+h for KB shortcuts

Bash

Reading from bash

1
2
3
4
5
6
while read -p 'Message for notifying the reading'; do
if [[ ! -z "${REPLY}" ]]; then
VARIABLE=$REPLY
    break
fi
done
https://snipt.net/embed/e1de0c8cd8a1635028e3083732a631a2/
/raw/e1de0c8cd8a1635028e3083732a631a2/
e1de0c8cd8a1635028e3083732a631a2
bash
Bash
6
2019-06-18T08:36:52
True
False
False
/api/public/snipt/6511/
reading-from-bash
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="k">while</span> <span class="nb">read</span> -p <span class="s1">&#39;Message for notifying the reading&#39;</span><span class="p">;</span> <span class="k">do</span> </span><span id="L-2"><a name="L-2"></a><span class="k">if</span> <span class="o">[[</span> ! -z <span class="s2">&quot;</span><span class="si">${</span><span class="nv">REPLY</span><span class="si">}</span><span class="s2">&quot;</span> <span class="o">]]</span><span class="p">;</span> <span class="k">then</span> </span><span id="L-3"><a name="L-3"></a><span class="nv">VARIABLE</span><span class="o">=</span><span class="nv">$REPLY</span> </span><span id="L-4"><a name="L-4"></a> <span class="nb">break</span> </span><span id="L-5"><a name="L-5"></a><span class="k">fi</span> </span><span id="L-6"><a name="L-6"></a><span class="k">done</span> </span></pre></div> </td></tr></table>
read