You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
668 B

  1. ##
  2. # return 0 (true) if array (passed by name) contains element
  3. # usage:
  4. # ARRAY = ( a b c )
  5. # containsElement ARRAY 'a' => 0
  6. containsElement () {
  7. local -a 'arraykeys=("${!'"$1"'[@]}")'
  8. for index in ${arraykeys[*]}; do
  9. current=$1"[$index]"
  10. [[ "${!current}" == "$2" ]] && return 0; # found
  11. done
  12. return 1; # not found
  13. }
  14. ##
  15. #
  16. askConfirmation () {
  17. case "$1" in
  18. y|Y|yes|YES )
  19. QUESTION="(Y/n)?"
  20. DEFAULT=0
  21. ;;
  22. * )
  23. QUESTION="(y/N)?"
  24. DEFAULT=1
  25. ;;
  26. esac
  27. read -p "$QUESTION : " choice
  28. case "$choice" in
  29. y|Y|yes|YES ) return 0;; #true
  30. n|no|N|NO ) return 1;; #false
  31. * ) return $DEFAULT;;
  32. esac
  33. }