Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
bash:cheat [2025-03-21] dcaibash:cheat [2025-03-21] (current) dcai
Line 12: Line 12:
 === 💻 File condition tests === === 💻 File condition tests ===
  
-<code sh>+<code bash>
 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 ===
  
-<code sh>+<code bash>
 if test $? = 0; then if test $? = 0; then
   echo 'do this';   echo 'do this';
Line 44: Line 44:
 === 💻 Variable condition tests === === 💻 Variable condition tests ===
  
-<code sh>+<code bash>
 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 ===
  
-<code sh>+<code bash>
 if !type brew &>/dev/null; then if !type brew &>/dev/null; then
   echo "brew install"   echo "brew install"
Line 130: Line 130:
 === 💻 For === === 💻 For ===
  
-<code sh>+<code bash>
 for name [in list] for name [in list]
 do do
Line 139: Line 139:
 === 💻 Case === === 💻 Case ===
  
-<code sh>+<code bash>
 case expression in case expression in
   pattern1 )   pattern1 )
Line 172: Line 172:
 === 💻 Search === === 💻 Search ===
  
-<code sh>+<code bash>
 find . -iname "*filename*" find . -iname "*filename*"
 find . -type d find . -type d
 </code> </code>
  
bash/cheat.1742554667.txt.gz · Last modified: by dcai