Advertisement
Guest User

Untitled

a guest
May 26th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. **interpreter directive**: `#!/bin/bash`
  2. **special characters**: `" "` expands | `' '` literal | `(( ))` arithmetic expansion
  3. **globs**: `*` any string | `?` one character | `[..]` any one of the characters | cannot match `/`
  4. **background**: `cmd &` at end of the line
  5.  
  6. **pipe**: `cmd1 | cmd2` connects cmd1's stdout to cmd2's stdin
  7. **redirection**:
  8. - `cmd ? file`: `>` | `1>` | `2>` | `<` | `0<` | `>>` append
  9. - `cmd ? string`: `<< EOF <Enter> Line 1, 2, 3, ... <Enter> EOF` multiline | `<<<` one-line
  10.  
  11. **process substitution**: `cmd1 <(cmd2) <(cmd3)` pipes cmd2 & cmd3's stdout to cmd1 via temporary files
  12.  
  13. **execute commands** `c` | `c1 && c2` | `c1 || c2` | `!c` negate
  14.  
  15. **env variables**:`BASH_VERSION` | `HOSTNAME` | `PPID` | `PWD` | `RANDOM` [0, 32767] | `UID` | `COLUMNS` width | `LINES` height | `HOME` | `PATH` | `PS1` prompt format | `SHELL` | `TMPDIR`
  16.  
  17. **variable types**: `--` string "abc" | `-a` array ("a" "b") | `-i` integer 123 | `-r` read only | `-x` export
  18. - `a="hello"; declare -p a;` outputs `declare -- a="hello"`
  19. - **array**: `arr=("x" "y")` | `arr=([0]="x" [5]="y")` | `files=(*)` | `"${arr[@]}"` "x" "y" | `"${arr[*]}"` "x y" | `"${#arr[@]}"` len | `"${!arr[@]}"` indices
  20.  
  21. **special parameters**: `$0` name | `$1 $2 ... ${10} ...` args | `"$*"` args joined | `"$@"` args list | `$#` args count | `$?` exit code of last cmd | `$$` PID | `$!` PID of last bg cmd | `"$_"` last arg of last cmd
  22.  
  23. **parameter expansion** `${...}`: `parameter:-word` w if unset | `parameter:=word` para=w if unset | `parameter:+word` w if set | `parameter:offset:length` substring | `#parameter` len | `parameter#pattern` del shortest prefix match | `parameter##pattern` del longest prefix match | `parameter%pattern` del shortest suffix match | `parameter%%pattern` del longest suffix match |`parameter/pattern/string` replace first match with string | `parameter//pattern/string` replace all matches with string | `parameter/#/string` prepend string | `parameter/%/string` append string
  24.  
  25. **brace expansion**: `{1..3}` 1 2 3 | `a{1,2,3}b` a1b a2b a3b
  26.  
  27. `[[ ... ]]`:
  28. - `-? FILE`: `e` exists | `s` not empty | `f` reg | `d` dir | `h` symlink | `r` readable | `w` writable | `x` executable | `O` I own | `G` my group owns
  29. - `-t FD` opened on a terminal | `-p PIPE` exists | `! EXPR`
  30. - `FILE1 -?? FILE2`: `nt` newer | `ot` older
  31. - `-? STRING`: `z` empty | `n` not empty
  32. - `STRING ? STRING`: `=` | `!=` | `<` | `>`
  33. - `STRING ? PATTERN`: `=` | `!=` | `=~` regex
  34. - `INT ?? INT`: `eq` | `ne` | `lt` | `gt` | `le` | `ge`
  35. - `( EXPR )` | `EXPR && EXPR` | `EXPR || EXPR`
  36.  
  37. **control flow**:
  38. - `if c1; then c2; elif c3; then c4; fi;`
  39. - `while c1; do c2 (break | continue); done;`
  40. - `for var in words; do echo $var; done;`
  41. - `for ((i=0; i<3; i++)); do echo $i; done;`
  42. - `case var in pattern1) c1 ;& pattern2) c2 ;; *) c3;; esac;`: `;;` stop | `;&` fallthrough
  43.  
  44. read line from file: `while read line; do echo $line; done < file`
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement