aboutsummaryrefslogtreecommitdiffhomepage
path: root/print.html
diff options
context:
space:
mode:
authorjohannst <johannst@users.noreply.github.com>2020-04-11 22:59:21 +0000
committerjohannst <johannst@users.noreply.github.com>2020-04-11 22:59:21 +0000
commit0b8ec70afa871d77b86501015793f155689b1fc3 (patch)
tree8d2697bc5a8c7b5f9578273b8599576638ed373d /print.html
parenta3b9bee22eea30b8b8ffbf30a43c53c5742f834a (diff)
downloadnotes-0b8ec70afa871d77b86501015793f155689b1fc3.tar.gz
notes-0b8ec70afa871d77b86501015793f155689b1fc3.zip
deploy: f81b1f23a526450e16992e2e248495365d9e394d
Diffstat (limited to 'print.html')
-rw-r--r--print.html81
1 files changed, 79 insertions, 2 deletions
diff --git a/print.html b/print.html
index 66d3abe..d1b2fbb 100644
--- a/print.html
+++ b/print.html
@@ -379,9 +379,55 @@ As we can see the offset from relocation at index <code>0</code> points to <code
</code></pre>
<h3><a class="header" href="#parameter" id="parameter">Parameter</a></h3>
<pre><code class="language-bash"># default param
-# if $foo set, then bar=$foo else bar=some_val
-bar=${foo:-some_val}
+bar=${foo:-some_val} # if $foo set, then bar=$foo else bar=some_val
+
+# check param set
+bar=${foo:?msg} # if $foo set, then bar=$foo else exit and print msg
+
+# indirect
+FOO=foo
+BAR=FOO
+bar=${!BAR} # deref value of BAR -&gt; bar=$FOO
+
+# prefix
+${foo#prefix} # remove prefix when expanding $foo
+# suffix
+${foo%suffix} # remove suffix when expanding $foo
+
+# substitute
+${foo/pattern/string} # replace pattern with string when expanding foo
+# pattern starts with
+# '/' replace all occurences of pattern
+# '#' pattern match at beginning
+# '%' pattern match at end
</code></pre>
+<blockquote>
+<p>Note: <code>prefix</code>/<code>suffix</code>/<code>pattern</code> are expanded as <a href="bash.html#pathname">pathnames</a>.</p>
+</blockquote>
+<h3><a class="header" href="#pathname" id="pathname">Pathname</a></h3>
+<pre><code class="language-bash">* match any string
+? match any single char
+\\ match backslash
+[abc] match any char of 'a' 'b' 'c'
+[a-z] match any char between 'a' - 'z'
+[^ab] negate, match all not 'a' 'b'
+[:class:] match any char in class, available:
+ alnum,alpha,ascii,blank,cntrl,digit,graph,lower,
+ print,punct,space,upper,word,xdigit
+</code></pre>
+<p>Wit <code>extglob</code> shell option enabled it is possible to have more powerful
+patterns. In the following <code>pattern-list</code> is one ore more patterns separated
+by <code>|</code> char.</p>
+<pre><code class="language-bash">?(pattern-list) matches zero or one occurrence of the given patterns
+*(pattern-list) matches zero or more occurrences of the given patterns
++(pattern-list) matches one or more occurrences of the given patterns
+@(pattern-list) matches one of the given patterns
+!(pattern-list) matches anything except one of the given patterns
+</code></pre>
+<blockquote>
+<p>Note: <code>shopt -s extglob</code>/<code>shopt -u extglob</code> to enable/disable <code>extglob</code>
+option.</p>
+</blockquote>
<h2><a class="header" href="#io-redirection" id="io-redirection">I/O redirection</a></h2>
<blockquote>
<p>Note: The trick with bash I/O redirection is to interpret from left-to-right.</p>
@@ -405,6 +451,37 @@ command 2&gt;&amp;1 &gt;file
<li>duplicate <code>fd 1</code> to <code>fd 2</code>, effectively redirecting <code>stderr</code> to <code>stdout</code></li>
<li>redirect <code>stdout</code> to <code>file</code></li>
</ol>
+<h2><a class="header" href="#completion" id="completion">Completion</a></h2>
+<p>The <code>complete</code> builtin is used to interact with the completion system.</p>
+<pre><code class="language-bash">complete # print currently installed completion handler
+complete -F &lt;func&gt; &lt;cmd&gt; # install &lt;func&gt; as completion handler for &lt;cmd&gt;
+complete -r &lt;cmd&gt; # uninstall completion handler for &lt;cmd&gt;
+</code></pre>
+<p>Variables available in completion functions:</p>
+<pre><code class="language-bash"># in
+$1 # &lt;cmd&gt;
+$2 # current word
+$3 # privous word
+
+COMP_WORDS # array with current command line words
+COMP_CWORD # index into COMP_WORDS with current cursor position
+
+# out
+COMPREPLY # array with possible completions
+</code></pre>
+<p><code>compgen</code> builtin is used to generate possible matches for <code>word</code> out of possible <code>option</code>s.
+The syntax is as follows:</p>
+<pre><code class="language-bash">compgen [option] [word]
+
+# usefule options:
+
+# -W &lt;list&gt; compare against word-list
+compgen -W &quot;foo foobar bar&quot; &quot;f&quot;
+
+# -d compare against dir names
+# -f compare against file names
+compgen -d -f &quot;hom&quot;
+</code></pre>
<h1><a class="header" href="#tmux1" id="tmux1">tmux(1)</a></h1>
<p>Terminology:</p>
<ul>