-3

I was reading this post and found it useful for a script I am trying to write, but where do I put the code to execute if the proper input is given.

My code is as such:

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

Now the code i am trying to execute (with confirmation) is:

apt-get install vsftpd

So where does that code actually go? I might just be dumb when it comes to this, but I cannot figure this out.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
  • 2
    use a process of elimination. Does it make sense to execute the `N` branch and `exit`? What is left? Or do you need to search for a tutorial that includes a `case ... esac` example? There should be many out there, or search here `[bash] esac` would probably be enough. Good luck. – shellter Jan 30 '18 at 00:29
  • Replace `make install` with whichever command you want. – that other guy Jan 30 '18 at 00:32

1 Answers1

0

Thanks to @that other guy and @Charles Duffy, i fixed my script by making the script code as follows:

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

Replace $program-name with whatever, and $code with the code you want confirmation for.