- Published on
Bashでyes/noでスクリプトの続行を確認する
- Authors
- Name
- Shou Arisaka / 有坂翔
LinuxコマンドラインのBashでyes/noでスクリプトの続行を確認する方法について紹介します。

以下のスクリプトをわかりやすく使いやすくしてみた。
How do I prompt a user for confirmation in bash script? - Stack Overflow
ok(){
: <<< '
yes or no prompt
e.g. printf "The file alredy exist here. Overwrite it? " ; ok && echo y || echo n
'
read -n 1 -r ; [[ $REPLY =~ ^[Yy]$ ]] && return 0 || return 1
}
使用例
printf "The file alredy exist here. Overwrite it? " ; ok && echo y || echo n