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.
32 lines
710 B
32 lines
710 B
#!/bin/sh |
|
|
|
ask_yn() { |
|
default=${2:-"y"} |
|
default=$(printf "%s" "$default" | tr '[:upper:]' '[:lower:]') |
|
|
|
# Set prompt string |
|
case "$default" in |
|
y) prompt="Y/n" ;; |
|
n) prompt="y/N" ;; |
|
*) printf "Invalid default answer\n"; exit 1 ;; |
|
esac |
|
|
|
while true; do |
|
trap 'exit' INT |
|
printf "%s (%s): " "$1" "$prompt" |
|
read -r answer || exit |
|
if [ -z "$answer" ]; then |
|
answer="$default" |
|
break |
|
fi |
|
case "$answer" in |
|
y|Y) answer="y"; break;; |
|
n|N) answer="n"; break;; |
|
esac |
|
done |
|
|
|
case "$answer" in |
|
y|Y) printf "1";; |
|
n|N) printf "0";; |
|
esac |
|
} |