From bac8a5d2822835cf47175d1162030653fadd5c09 Mon Sep 17 00:00:00 2001 From: johannst Date: Thu, 15 Feb 2024 23:29:57 +0000 Subject: deploy: 4485708c972815bbb6df7f5a228683aa855d553d --- tools/bash.html | 47 ++++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 17 deletions(-) (limited to 'tools/bash.html') diff --git a/tools/bash.html b/tools/bash.html index 580e941..91d44cb 100644 --- a/tools/bash.html +++ b/tools/bash.html @@ -192,7 +192,7 @@ bar=${foo:-some_val} # if $foo set, then bar=$foo else bar=some_val # alternate value -bar=${foo:+bla $foo} # if $foo set, then bar="bla $foo" else bar="" +bar=${foo:+bla $foo} # if $foo set, then bar="bla $foo" else bar="" # check param set bar=${foo:?msg} # if $foo set, then bar=$foo else exit and print msg @@ -274,6 +274,19 @@ contains some nice visualization to explain bash redirections.

once.

vim -d <(grep foo bar) <(grep foo moose)
 
+

Command grouping

+

Execute commands in a group with or without subshell. Can be used to easily +redirect stdout/stderr of all commands in the group into one file.

+
# Group commands without subshell.
+v=abc ; { v=foo; echo $v; } ; echo $v
+# foo
+# foo
+
+# Group commands with subshell.
+v=abc ; ( v=foo; echo $v; ) ; echo $v
+# foo
+# abc
+

Argument parsing with getopts

The getopts builtin uses following global variables: