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
- duplicate
fd 1
tofd 2
, effectively redirectingstderr
tostdout
- redirect
stdout
tofile