在Y / N确认时,我在哪里放置实际命令?

时间:2018-01-30 00:18:32

标签: bash shell while-loop

我正在阅读this post并发现它对我正在尝试编写的脚本很有用,但是如果给出了正确的输入,我在哪里可以执行代码。

我的代码是这样的:

while true; do
    read -p "Do you wish to install this program?" yn 
    case $yn in
        [Yy]* ) make install; break;;
        [Nn]* ) exit;;
        * ) echo "Yes or No";; 
    esac 
done

现在我尝试执行的代码(确认)是:

apt-get install vsftpd

那么代码实际上去了哪里?谈到这一点,我可能只是愚蠢,但我无法理解这一点。

1 个答案:

答案 0 :(得分:0)

感谢@that其他人和@Charles Duffy,我通过制作如下脚本代码修复了我的脚本:

while true; do
    read -p "Do you wish to install $program-name?: " yn 
    case $yn in
        [Yy]* ) echo "some code here"; break;;
        [Nn]* ) break;;
        * ) echo "Yes or No";; 
     esac 
done

$program-name替换为任何内容,将$code替换为您要确认的代码。