Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # (@)/ph
  4. # A very simple telephone list
  5. # Type "ph new name number" to add to the list, or
  6. # just type "ph name" to get a phone number
  7.  
  8.  
  9. PHONELIST=~/.phonelist.txt
  10.  
  11. # If no command line parameters ($#), there
  12. # is a problem, so ask what they're talking about.
  13. if [ $# -lt 1 ] ; then
  14. echo "Whose phone number did you want? "
  15. exit 1
  16. fi
  17.  
  18. # Did you want to add a new phone number?
  19. if [ $1 = "new" ] ; then
  20. shift
  21. echo $* >> $PHONELIST
  22. echo $* added to database
  23. exit 0
  24. fi
  25.  
  26. # Nope. But does the file have anything in it yet?
  27. # This might be our first time using it, after all.
  28. if [ ! -s $PHONELIST ] ; then
  29. echo "No names in the phone list yet! "
  30. exit 1
  31. else
  32. grep -i -q "$*" $PHONELIST # Quietly search the file
  33. if [ $? -ne 0 ] ; then # Did we find anything?
  34. echo "Sorry, that name was not found in the phone list"
  35. exit 1
  36. else
  37. grep -i "$*" $PHONELIST
  38. fi
  39. fi
  40. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement