Advertisement
peetaur

grep in an if

Mar 11th, 2014
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.41 KB | None | 0 0
  1. 2 ways to do it:
  2. ===============================
  3. # using >/dev/null 2>&1 to prevent any output
  4. grep "$WORKINGDIR" ~/.bak.cfg >/dev/null 2>&1
  5. checkDir=$?
  6.  
  7. if [ $checkDir != 0 ]; then
  8.     echo "Path doesn't exist!";
  9. else
  10.     echo "Path exists!";
  11. fi
  12. ===============================
  13. # no [ ] used here
  14. if grep "$WORKINGDIR" ~/.bak.cfg >/dev/null 2>&1; then
  15.     echo "Path doesn't exist!";
  16. else
  17.     echo "Path exists!";
  18. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement