Guest User

Untitled

a guest
Nov 19th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. arga=0
  4. argb=0
  5. argc=0
  6.  
  7. printUsage () {
  8. echo "\nSupported options:"
  9. echo "------------------"
  10. echo "\t-a\targa\tDoes something called 'a'"
  11. echo "\t-b\targb\tDoes something called 'b'"
  12. echo "\t-c\targc\tDoes something called 'c'"
  13. }
  14.  
  15. # cmd line options processing
  16. processOptions () {
  17. while getopts "abc" optname
  18. do
  19. case "$optname" in
  20. "a")
  21. arga=1
  22. ;;
  23. "b")
  24. argb=1
  25. ;;
  26. "c")
  27. argc=1
  28. ;;
  29. *)
  30. printUsage
  31. exit
  32. ;;
  33. esac
  34. done
  35. return $OPTIND
  36. }
  37.  
  38. processOptions "$@"
  39.  
  40. if [ "$arga" -eq "1" ]; then
  41. echo "-a was passed"
  42. fi
  43. if [ "$argb" -eq "1" ]; then
  44. echo "-b was passed"
  45. fi
  46. if [ "$argc" -eq "1" ]; then
  47. echo "-c was passed"
  48. fi
Add Comment
Please, Sign In to add comment