summaryrefslogtreecommitdiff
path: root/posts/6/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'posts/6/index.html')
-rw-r--r--posts/6/index.html18
1 files changed, 9 insertions, 9 deletions
diff --git a/posts/6/index.html b/posts/6/index.html
index 2828d15..4baa0c6 100644
--- a/posts/6/index.html
+++ b/posts/6/index.html
@@ -149,7 +149,7 @@ Redirection File Redirection 0 is standard input, 1 is standard output, 2 is sta
<p>the connection to the stream used by FD <code>y</code> is copied to FD <code>x</code></p>
<p><code>curl cip.cc &gt; result 2&gt;&amp;1</code></p>
<p><code>ping localhost &gt; result 2&gt;&amp;1</code></p>
-<div class="highlight"><pre tabindex="0" style="background-color:#fff;-moz-tab-size:2;-o-tab-size:2;tab-size:2;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="font-style:italic"># exec can be used to change the file descriptors of bash itself,</span>
+<div class="highlight"><pre tabindex="0" style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="font-style:italic"># exec can be used to change the file descriptors of bash itself,</span>
</span></span><span style="display:flex;"><span><span style="font-style:italic"># and if you use an x that doesn&#39;t yet exist,</span>
</span></span><span style="display:flex;"><span><span style="font-style:italic"># bash will create a new file descriptor (&#34;plug&#34;) for you with that number.</span>
</span></span><span style="display:flex;"><span><span style="font-style:italic"># - in command is to close new FD 3 we&#39;d created before.</span>
@@ -172,13 +172,13 @@ Redirection File Redirection 0 is standard input, 1 is standard output, 2 is sta
<p><code>ping localhost &amp;&gt;result</code></p>
</blockquote>
<h3 id="here-documents">Here documents</h3>
-<div class="highlight"><pre tabindex="0" style="background-color:#fff;-moz-tab-size:2;-o-tab-size:2;tab-size:2;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="font-style:italic">&lt;&lt;delimiter
+<div class="highlight"><pre tabindex="0" style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="font-style:italic">&lt;&lt;delimiter
</span></span></span><span style="display:flex;"><span><span style="font-style:italic"> Here document
</span></span></span><span style="display:flex;"><span><span style="font-style:italic">delimiter</span>
</span></span></code></pre></div><p>Make FD 0 read from the string between <code>delimiter</code>s</p>
<blockquote>
<p>Here-Documents are great for reading blocks of text to command line.</p>
-<div class="highlight"><pre tabindex="0" style="background-color:#fff;-moz-tab-size:2;-o-tab-size:2;tab-size:2;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>cat <span style="font-style:italic">&lt;&lt; EOF
+<div class="highlight"><pre tabindex="0" style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>cat <span style="font-style:italic">&lt;&lt; EOF
</span></span></span><span style="display:flex;"><span><span style="font-style:italic">this is within here document
</span></span></span><span style="display:flex;"><span><span style="font-style:italic">I can write as many lines as I like
</span></span></span><span style="display:flex;"><span><span style="font-style:italic">and terminate with line of demiliter only
@@ -189,7 +189,7 @@ Redirection File Redirection 0 is standard input, 1 is standard output, 2 is sta
<p>Make FD 0 read from the <code>string</code></p>
<blockquote>
<p>Here strings are very similar to here documents but more concise. They are generally preferred over here documents.</p>
-<div class="highlight"><pre tabindex="0" style="background-color:#fff;-moz-tab-size:2;-o-tab-size:2;tab-size:2;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>cat &lt;&lt;&lt; <span style="font-style:italic">&#34;This,
+<div class="highlight"><pre tabindex="0" style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>cat &lt;&lt;&lt; <span style="font-style:italic">&#34;This,
</span></span></span><span style="display:flex;"><span><span style="font-style:italic">is the here strings. tab will also be read.&#34;</span>
</span></span></code></pre></div></blockquote>
<h3 id="moving-file-decipher">Moving file decipher</h3>
@@ -197,7 +197,7 @@ Redirection File Redirection 0 is standard input, 1 is standard output, 2 is sta
<p>Replace FD <code>x</code> with FD <code>y</code> and close FD <code>y</code></p>
<blockquote>
<p>Easy way of <code>[x]&gt;&amp;y, y&gt;&amp;-</code></p>
-<div class="highlight"><pre tabindex="0" style="background-color:#fff;-moz-tab-size:2;-o-tab-size:2;tab-size:2;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="font-style:italic"># 3&gt;&amp;1-: copy FD 1 to FD 3 and close FD 1.</span>
+<div class="highlight"><pre tabindex="0" style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="font-style:italic"># 3&gt;&amp;1-: copy FD 1 to FD 3 and close FD 1.</span>
</span></span><span style="display:flex;"><span><span style="font-style:italic"># &gt;&amp;3-: copy FD 3 to FD 1 and close FD 3.</span>
</span></span><span style="display:flex;"><span>exec 3&gt;&amp;1- &gt;mylog; echo moo; exec &gt;&amp;3-
</span></span></code></pre></div></blockquote>
@@ -206,7 +206,7 @@ Redirection File Redirection 0 is standard input, 1 is standard output, 2 is sta
<p>Open FD <code>x</code> for both reading and writing to <code>file</code></p>
<blockquote>
<p>The file descriptor at x is opened with a stream to the file that can be used for writing as well as reading bytes. Usually you&rsquo;ll use two file descriptors for this. <strong>One of the rare cases where this is useful is when setting up a stream with a read/write device such as a network socket</strong>.</p>
-<div class="highlight"><pre tabindex="0" style="background-color:#fff;-moz-tab-size:2;-o-tab-size:2;tab-size:2;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>exec 5&lt;&gt;aFile
+<div class="highlight"><pre tabindex="0" style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>exec 5&lt;&gt;aFile
</span></span><span style="display:flex;"><span>cat &gt;&amp;5 <span style="font-style:italic">&#34;Hello world&#34;</span> <span style="font-style:italic"># make FD 1 write to where FD 5 currently writing, copy file descriptor FD 5 to FD 1</span>
</span></span><span style="display:flex;"><span>cat &lt;&amp;5 <span style="font-style:italic"># make FD 0 read from where FD 5 currently reading, copy file descriptor FD 5 to FD 0, then cat will send content to FD 1</span>
</span></span></code></pre></div></blockquote>
@@ -248,7 +248,7 @@ zsh. : <code>setopt extendedglob</code>
</ol>
<h3 id="command-substitution">Command Substitution</h3>
<p>we can expansion commands within commands, but must use double-quote <code>&quot;&quot;</code> instead of <code>''</code></p>
-<div class="highlight"><pre tabindex="0" style="background-color:#fff;-moz-tab-size:2;-o-tab-size:2;tab-size:2;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="font-style:italic"># this will output contents in hello.h to screen</span>
+<div class="highlight"><pre tabindex="0" style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="font-style:italic"># this will output contents in hello.h to screen</span>
</span></span><span style="display:flex;"><span>cat hello.h
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="font-style:italic"># this will expand `cat hello.h` to real contents in </span>
@@ -296,7 +296,7 @@ zsh. : <code>setopt extendedglob</code>
<p>In addition, we can put braces (<code>{</code> and <code>}</code>) around our parameter, which indicates where variable is about to begin and end.</p>
<blockquote>
<p>e.g. <code>name=orange; echo there are 4 &quot;${name}s&quot;</code> <code>there are 4 oranges</code>.</p>
-<div class="highlight"><pre tabindex="0" style="background-color:#fff;-moz-tab-size:2;-o-tab-size:2;tab-size:2;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>name=orange
+<div class="highlight"><pre tabindex="0" style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>name=orange
</span></span><span style="display:flex;"><span>echo <span style="font-style:italic">&#34;there are 4 </span><span style="font-weight:bold;font-style:italic">${</span>name<span style="font-weight:bold;font-style:italic">}</span><span style="font-style:italic">s.&#34;</span> <span style="font-style:italic"># there are 4 oranges.</span>
</span></span><span style="display:flex;"><span>echo <span style="font-style:italic">&#34;there are 4 </span>$names<span style="font-style:italic">.&#34;</span> <span style="font-style:italic"># there are 4 .</span>
</span></span></code></pre></div><p>here, we put <code>{}</code>around<code>name</code>so that bash can be told that suffix <code>s</code> is not a part of variable. otherwise, it will treat <code>names</code> as parameter and looking for its value, which is none in our example.</p>
@@ -305,7 +305,7 @@ zsh. : <code>setopt extendedglob</code>
<blockquote>
<p>While expanding a parameter, it is possible to apply an operator to the expanding value without alternate original value.</p>
<p>I use these mostly</p>
-<div class="highlight"><pre tabindex="0" style="background-color:#fff;-moz-tab-size:2;-o-tab-size:2;tab-size:2;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="font-style:italic"># remove string before pattern ${name#pattern} shortest ${name##pattern} longest</span>
+<div class="highlight"><pre tabindex="0" style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="font-style:italic"># remove string before pattern ${name#pattern} shortest ${name##pattern} longest</span>
</span></span><span style="display:flex;"><span><span style="font-style:italic"># remove string after pattern ${name%pattern} longest ${name%%pattern} shortest</span>
</span></span><span style="display:flex;"><span><span style="font-style:italic"># delete first matching pattern ${name/pattern}</span>
</span></span><span style="display:flex;"><span><span style="font-style:italic"># delete all matching pattern ${name//pattern}</span>