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 12: | Line 12: | ||
| === 💻 File condition tests === | === 💻 File condition tests === | ||
| - | < | + | < |
| if [[ -f filename ]]; then | if [[ -f filename ]]; then | ||
| # file exists | # file exists | ||
| Line 34: | Line 34: | ||
| === 💻 check last command status code === | === 💻 check last command status code === | ||
| - | < | + | < |
| if test $? = 0; then | if test $? = 0; then | ||
| echo 'do this'; | echo 'do this'; | ||
| Line 44: | Line 44: | ||
| === 💻 Variable condition tests === | === 💻 Variable condition tests === | ||
| - | < | + | < |
| if [[ -z $? ]]; then | if [[ -z $? ]]; then | ||
| # last command run successfully | # last command run successfully | ||
| Line 74: | Line 74: | ||
| === 💻 check if command available === | === 💻 check if command available === | ||
| - | < | + | < |
| if !type brew &>/ | if !type brew &>/ | ||
| echo "brew install" | echo "brew install" | ||
| Line 130: | Line 130: | ||
| === 💻 For === | === 💻 For === | ||
| - | < | + | < |
| for name [in list] | for name [in list] | ||
| do | do | ||
| Line 139: | Line 139: | ||
| === 💻 Case === | === 💻 Case === | ||
| - | < | + | < |
| case expression in | case expression in | ||
| pattern1 ) | pattern1 ) | ||
| Line 172: | Line 172: | ||
| === 💻 Search === | === 💻 Search === | ||
| - | < | + | < |
| find . -iname " | find . -iname " | ||
| find . -type d | find . -type d | ||
| </ | </ | ||