Advertisement
Guest User

Untitled

a guest
Oct 13th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. ALL=false
  4. PATH=./
  5.  
  6. usage()
  7. {
  8. echo "Usage: $0 WORD [-a] [ -p PATH ]"
  9. exit 2
  10. }
  11.  
  12. if [ $# = 0 ]
  13. then
  14. usage
  15. fi
  16.  
  17. WORD=$1
  18. shift
  19.  
  20. while getopts 'ap:' OPTION
  21. do
  22. case ${OPTION} in
  23. a)
  24. ALL=true ;;
  25. p)
  26. PATH=$OPTARG ;;
  27. esac
  28. done
  29.  
  30. if [ "$ALL" = true ]
  31. then
  32. RESULT=$(/bin/grep -lR ${WORD} $PATH)
  33. else
  34. RESULT=$(/bin/grep -lR --include \*.txt --include \*.sh ${WORD} $PATH)
  35. fi
  36.  
  37. echo "$RESULT"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement