fork download
  1. #!/bin/bash
  2.  
  3. command_to_do() {
  4. echo "Args $@"
  5.  
  6. SYSTEM=false
  7. UNINSTALL=false
  8. PUSH=false
  9. VERSION="debug"
  10.  
  11. while getopts "sup:" opt; do
  12. printf "\n$opt\n"
  13. case $opt in
  14. s) echo "Setting SYSTEM to true"
  15. SYSTEM=true
  16. ;;
  17. p) echo "Setting VERSION to $OPTARG"
  18. PUSH=true
  19. VERSION=$OPTARG
  20. ;;
  21. u) echo "Setting UNINSTALL to true"
  22. UNINSTALL=true
  23. ;;
  24. esac
  25. done
  26.  
  27. printf "\nSystem: $SYSTEM\nVersion: $VERSION\n"
  28.  
  29. if [[ $UNINSTALL = true ]]; then
  30. if [[ $SYSTEM = true ]]; then
  31. echo "system uninstall"
  32. else
  33. echo "non-system uninstall"
  34. fi
  35. fi
  36.  
  37. }
  38.  
  39. echo
  40. echo "------------ First run:"
  41. command_to_do -s -p release
  42.  
  43. echo
  44. echo "------------ Second run: (no reset)"
  45. command_to_do -s -p release
  46.  
  47. echo
  48. echo "------------ Third run (OPTIND reset)"
  49. unset OPTIND
  50. command_to_do -s -p release
Success #stdin #stdout 0s 19664KB
stdin
Standard input is empty
stdout
------------ First run:
Args -s -p release

s
Setting SYSTEM to true

p
Setting VERSION to release

System: true
Version: release

------------ Second run: (no reset)
Args -s -p release

System: false
Version: debug

------------ Third run (OPTIND reset)
Args -s -p release

s
Setting SYSTEM to true

p
Setting VERSION to release

System: true
Version: release