Skip to content

Instantly share code, notes, and snippets.

@katoy
Created March 12, 2014 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save katoy/9507953 to your computer and use it in GitHub Desktop.
Save katoy/9507953 to your computer and use it in GitHub Desktop.
yes/no を聞く bash スクリプト
#!/bin/bash
# bash で yes/no を聞く。
#
# See http://yuki.silk.to/2006/04/000161.html
# http://usaturn.net/memo/shell_tech_yesorno.html
function yes_no() {
echo "-------------------------------------------"
echo "よろしいですか?(yes/no)"
echo -n " => "
read ans
# echo "-------------------------------------------"
case ${ans} in
[Yy]|[Yy][Ee][Ss])
echo "yes が選択されました。"
return 0 ;;
[Nn]|[Nn][Oo])
echo "no が選択されました。"
return 1 ;;
*)
yes_no ;;
esac
}
yes_no
ans=$?
echo "#--- yes_no() return ${ans}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment