シェルスクリプトでシンプルな対話形式する
1519 ワード
ファイル作成
test.sh
#!/bin/bash
function ConfirmExecution() {
echo "スクリプトを実行しますか? y/n"
read input
if [ -z $input ] ; then
ConfirmExecution
elif [ $input = 'y' ] ; then
echo "スクリプトを実行します。"
else
echo "スクリプトを終了します。"
exit 1
fi
}
ConfirmExecution
echo "Hello world!"
実行
./test.sh
まとめ
test.sh
#!/bin/bash
function ConfirmExecution() {
echo "スクリプトを実行しますか? y/n"
read input
if [ -z $input ] ; then
ConfirmExecution
elif [ $input = 'y' ] ; then
echo "スクリプトを実行します。"
else
echo "スクリプトを終了します。"
exit 1
fi
}
ConfirmExecution
echo "Hello world!"
./test.sh
まとめ
yを入力すると、Hello worldが出力され、
nを入力すると、その時点で処理が終了する。
Author And Source
この問題について(シェルスクリプトでシンプルな対話形式する), 我々は、より多くの情報をここで見つけました https://qiita.com/oblivion/items/7811e73fb16f3d155d81著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .