3.142.96.146 |    

Navigation

Google Advertisement

This function ask for a defined text and wait for (y/n) answer.
if confirm "Do they really want it?"; then
    # do something ;)
fi


confirm
  1. # *******************************************************
  2. # This function ask for a defined text and wait for (y/n) answer.
  3. # If no right answer was set, the function starte recusrivly again.
  4. #
  5. # @param $1 - The question text
  6. # @return bool
  7. #
  8. function confirm () {
  9.  
  10. local txt=$1
  11. local answer
  12.  
  13. read -p "${txt}" answer
  14. case $answer in
  15.         [Yy]*) return 0         ;;
  16.         [Nn]*) return 1         ;;
  17.                 *) echo -e "Please answer yes(y) or no(n).\n"; confirm "${txt}" ;;
  18. esac
  19.  
  20. }
Parsed in 0.002 seconds at 228.20 KB/s

Search
 
Full text search by name and content of a snippet.

User online
There are 7 users online.

Tags Cloud

Latest snippets
str2seconds
(Bash::Function)
is_integer
(Bash::Function)
file_rotate
(Bash::Function)
confirm
(Bash::Function)
is_workingtime
(Bash::Function)
last day of last month
(Bash::Snippets)
crypt_apr1_md5
(PHP::Function)
crypt_apr1_md5
(Perl::Function)
transparent
(CSS)
rfc2822Toiso8601
(PHP::Function)