diff options
author | johannst <johannes.stoelp@gmail.com> | 2020-03-21 12:50:12 +0100 |
---|---|---|
committer | johannst <johannes.stoelp@gmail.com> | 2020-03-21 12:50:12 +0100 |
commit | e2428a26e02e3274f475e7669c4dc963fdb6606a (patch) | |
tree | e284b06f41eb6c7aff46e30c2c81348bdbb54613 | |
parent | 6259d4ee6c06cc6ae4ce07484b75f7d327a6a52a (diff) | |
download | notes-e2428a26e02e3274f475e7669c4dc963fdb6606a.tar.gz notes-e2428a26e02e3274f475e7669c4dc963fdb6606a.zip |
added bash
-rw-r--r-- | src/SUMMARY.md | 1 | ||||
-rw-r--r-- | src/bash.md | 52 |
2 files changed, 53 insertions, 0 deletions
diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 80aced1..d50c46b 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -2,6 +2,7 @@ - [ld.so](./ld.so.md) - [git](./git.md) +- [bash](./bash.md) - [tmux](./tmux.md) - [awk](./awk.md) - [gdb](./gdb.md) diff --git a/src/bash.md b/src/bash.md new file mode 100644 index 0000000..0028724 --- /dev/null +++ b/src/bash.md @@ -0,0 +1,52 @@ +# bash(1) + +## Expansion + +### Generator + +```bash +# 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 +```bash +# 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. + +```bash +# stdout & stderr to file +command >file 2>&1 +# equivalent +command &>file + +# stderr to stdout & stdout to file +command 2>&1 >file +``` + +### Explanation + +```bash +j>&i +``` +Duplicate `fd i` to `fd j`, making `j` a copy of `i`. See [dup2(2)][dup2]. + +Example: +```bash +command 2>&1 >file +``` +1. duplicate `fd 1` to `fd 2`, effectively redirecting `stderr` to `stdout` +2. redirect `stdout` to `file` + +[dup2]: http://man7.org/linux/man-pages/man2/dup.2.html |