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-14T08:01:58
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

Bash

Substitution with sed from one file to another

sed -e 's/expression1/expression2/' source_file > target_file
https://snipt.net/embed/298b55f3e669cf33b8e8df407b4af9dd/
/raw/298b55f3e669cf33b8e8df407b4af9dd/
298b55f3e669cf33b8e8df407b4af9dd
bash
Bash
1
2019-06-12T10:28:24
True
False
False
/api/public/snipt/6510/
substitution-with-sed-from-one-file-to-another
<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>sed -e <span class="s1">&#39;s/expression1/expression2/&#39;</span> source_file &gt; target_file </span></pre></div> </td></tr></table>
file, sed, substitution, text