LoginSignup
3
3

More than 5 years have passed since last update.

bash で yesno

Last updated at Posted at 2014-10-20

LICENSE は NYSL / CC0 / THE BEER-WARE LICENSE とか適当に好きなの選んでください。

適宜 yeno を記載した functions.sh 作って、 source /path/to/functions.sh すると良いのかな。

コード

#! /usr/bin/env bash

function yesno() {
    printf '処理を開始します。 (Y/n) >> '
    read answer
    answer=`printf $answer | grep -iE '^(yes|y|no|n)$' | tr "[:lower:]" "[:upper:]"`
    case "$answer" in
        "Y" | "YES") return 0;;
        "N" | "NO") return 1;;
        *) yesno;;
    esac
}

yesno && echo 'yes'

使用例

$ ./yesno.sh
処理を開始します。 (Y/n) >> y
yes

THX: Shell

僕が所属している会社社員募集中みたいです。なんか、 Python とか何か書いてみてーなと思った人は応募してみてくださいな。 (すてま)

3
3
1

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
3
3