diff options
author | johannst <johannst@users.noreply.github.com> | 2020-04-11 22:59:21 +0000 |
---|---|---|
committer | johannst <johannst@users.noreply.github.com> | 2020-04-11 22:59:21 +0000 |
commit | 0b8ec70afa871d77b86501015793f155689b1fc3 (patch) | |
tree | 8d2697bc5a8c7b5f9578273b8599576638ed373d /print.html | |
parent | a3b9bee22eea30b8b8ffbf30a43c53c5742f834a (diff) | |
download | notes-0b8ec70afa871d77b86501015793f155689b1fc3.tar.gz notes-0b8ec70afa871d77b86501015793f155689b1fc3.zip |
deploy: f81b1f23a526450e16992e2e248495365d9e394d
Diffstat (limited to 'print.html')
-rw-r--r-- | print.html | 81 |
1 files changed, 79 insertions, 2 deletions
@@ -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 -> 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>&1 >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 <func> <cmd> # install <func> as completion handler for <cmd> +complete -r <cmd> # uninstall completion handler for <cmd> +</code></pre> +<p>Variables available in completion functions:</p> +<pre><code class="language-bash"># in +$1 # <cmd> +$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 <list> compare against word-list +compgen -W "foo foobar bar" "f" + +# -d compare against dir names +# -f compare against file names +compgen -d -f "hom" +</code></pre> <h1><a class="header" href="#tmux1" id="tmux1">tmux(1)</a></h1> <p>Terminology:</p> <ul> |