Advertisement
metalx1000

getops example

May 25th, 2015
1,146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.34 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. while getopts ":f:s:" arg; do
  4.   case "$arg" in
  5.     f)
  6.       f="${OPTARG}"
  7.       ;;
  8.     s)
  9.       s="${OPTARG}"
  10.       ;;
  11.   esac
  12. done
  13.  
  14. if [ "$f" = "True" ]
  15. then
  16.   echo "You entered 'True' for 'f'"
  17. else
  18.   echo "Defaulting to 'False' for 'f'"
  19. fi
  20.  
  21. if [ ! -z "${s}" ]
  22. then
  23.   echo "s is $s"
  24. else
  25.   echo "s is not set"
  26. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement