From a3b9bee22eea30b8b8ffbf30a43c53c5742f834a Mon Sep 17 00:00:00 2001 From: johannst Date: Sat, 21 Mar 2020 11:51:10 +0000 Subject: deploy: cb747f51cbe63e1302192eaf029ebdd4f1e154c0 --- bash.html | 258 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 258 insertions(+) create mode 100644 bash.html (limited to 'bash.html') diff --git a/bash.html b/bash.html new file mode 100644 index 0000000..3c937d9 --- /dev/null +++ b/bash.html @@ -0,0 +1,258 @@ + + + + + + bash - Notes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + + + +
+
+

bash(1)

+

Expansion

+

Generator

+
# generate sequence from n to m
+{n..m}
+# generate sequence from n to m step by s
+{n..m..s}
+
+# expand cartesian product
+{a,b}{c,d}
+
+

Parameter

+
# default param
+# if $foo set, then bar=$foo else bar=some_val
+bar=${foo:-some_val}
+
+

I/O redirection

+
+

Note: The trick with bash I/O redirection is to interpret from left-to-right.

+
+
# stdout & stderr to file
+command >file 2>&1
+# equivalent
+command &>file
+
+# stderr to stdout & stdout to file
+command 2>&1 >file
+
+

Explanation

+
j>&i
+
+

Duplicate fd i to fd j, making j a copy of i. See dup2(2).

+

Example:

+
command 2>&1 >file
+
+
    +
  1. duplicate fd 1 to fd 2, effectively redirecting stderr to stdout
  2. +
  3. redirect stdout to file
  4. +
+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3