This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| bash:cheat [2025-03-21] – dcai | bash:cheat [2025-03-21] (current) – dcai | ||
|---|---|---|---|
| Line 10: | Line 10: | ||
| * '' | * '' | ||
| - | === File condition tests === | + | === 💻 File condition tests === |
| - | < | + | < |
| if [[ -f filename ]]; then | if [[ -f filename ]]; then | ||
| - | | + | |
| else | else | ||
| - | | + | |
| fi | fi | ||
| + | # OR | ||
| + | [ -f ~/ | ||
| </ | </ | ||
| Line 30: | Line 32: | ||
| * file1 '' | * file1 '' | ||
| - | === Test last command status code === | + | === 💻 check last command status code === |
| - | < | + | < |
| if test $? = 0; then | if test $? = 0; then | ||
| echo 'do this'; | echo 'do this'; | ||
| Line 40: | Line 42: | ||
| </ | </ | ||
| - | === Condition | + | === 💻 Variable condition |
| - | < | + | < |
| if [[ -z $? ]]; then | if [[ -z $? ]]; then | ||
| # last command run successfully | # last command run successfully | ||
| Line 50: | Line 52: | ||
| fi | fi | ||
| - | [ -f ~/ | ||
| - | # or | ||
| [ -z " | [ -z " | ||
| [[ ! -z " | [[ ! -z " | ||
| Line 63: | Line 63: | ||
| * '' | * '' | ||
| - | == Conditionals | + | === 💻 numberic conditionals === |
| * '' | * '' | ||
| Line 72: | Line 72: | ||
| * '' | * '' | ||
| - | === check if command available === | + | === 💻 check if command available === |
| - | < | + | < |
| if !type brew &>/ | if !type brew &>/ | ||
| echo "brew install" | echo "brew install" | ||
| Line 88: | Line 88: | ||
| </ | </ | ||
| - | === Manipulating and/or expanding variables === | + | === 💻 Manipulating and/or expanding variables === |
| [[http:// | [[http:// | ||
| Line 116: | Line 116: | ||
| </ | </ | ||
| - | === Shortcuts === | + | === 💻 Shortcuts === |
| * CTRL L = Clear the screen | * CTRL L = Clear the screen | ||
| Line 128: | Line 128: | ||
| * !! = repeat last command | * !! = repeat last command | ||
| - | === For === | + | === 💻 For === |
| - | < | + | < |
| for name [in list] | for name [in list] | ||
| do | do | ||
| Line 137: | Line 137: | ||
| </ | </ | ||
| - | === Case === | + | === 💻 Case === |
| - | < | + | < |
| case expression in | case expression in | ||
| pattern1 ) | pattern1 ) | ||
| Line 148: | Line 148: | ||
| </ | </ | ||
| - | === $() vs backtick === | + | === 💻 $() vs backtick === |
| [[http:// | [[http:// | ||
| Line 154: | Line 154: | ||
| The backticks/ | The backticks/ | ||
| - | === Special bash variables === | + | === 💻 Special bash variables === |
| [[http:// | [[http:// | ||
| Line 170: | Line 170: | ||
| > The implementation of '' | > The implementation of '' | ||
| - | === Search === | + | === 💻 Search === |
| - | < | + | < |
| find . -iname " | find . -iname " | ||
| find . -type d | find . -type d | ||
| </ | </ | ||