LoginSignup
5

More than 5 years have passed since last update.

readで入力待ちの時、whileと組み合わせて想定文字以外のときにエラーを表示する

Posted at

y or n の例

echo -n "Are you sure you want to exit the server? [y/n] > "
while :
  do
    read INPUT
    case "$INPUT" in
      "y" ) kill $SERVER_PID
            echo "Stopped WEBRick"
            break ;;
      "n" ) echo "Canceled."
            break ;;
      * )   echo "[y/n] で入力してね!" ;;
    esac
  done

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5