0

I am pretty new to bash scripting and i have looked every where over the web and i have find several ways to simulate an enter push like you would normally do with php cli \n. But with my bash script it is not working as it should. Also the echo -ne \n | y stuff like that.

The problem is that i am trying to install a control panel (zpanel) ad have every question auto answered by bash. But how do i do this when the install script asks me if i want to continue. In this case i need to put in y and then press enter. Another question i just need to push enter and so on.

I hope some one can help me with this and how that is being handled in bash scripts.

thanks

carlosx2
  • 1,672
  • 16
  • 23
  • 2
    This is what tools like [`expect`](http://expect.sourceforge.net/) are for. – Etan Reisner Mar 03 '15 at 22:13
  • 2
    possible duplicate of [Simulating ENTER keypress in bash script](http://stackoverflow.com/questions/6264596/simulating-enter-keypress-in-bash-script) – Etan Reisner Mar 03 '15 at 22:14
  • the post didn't help me any further as i have tried that and it is not going to continue the install process. – carlosx2 Mar 03 '15 at 23:08
  • 1
    That question covers the main alternatives to what you want to do. `echo`, `yes`, and `expect`. It doesn't go into detail on `expect` but there are plenty of questions on this site and guides online about how to use it to do what you want. – Etan Reisner Mar 03 '15 at 23:18
  • If the installation involves `apt-get`, the proper solution is to preseed the debconf database with your answers. – tripleee Mar 04 '15 at 05:17

1 Answers1

0

If command is a command that asks for an input (for example a confirmation where you have to enter 'Y' or 'N'), this will do the trick:

echo "N" | command
christophetd
  • 3,834
  • 20
  • 33
  • ok i see, but what do you write where now command is written, or do you just write command. Many scripts just need y/n. thanks – carlosx2 Mar 30 '15 at 15:24
  • An example would be: `echo 'Y' | sudo apt-get install xxx` (even if in the case of apt-get install, you should use the -y option) – christophetd Mar 31 '15 at 14:28
  • yeah that is what i thought, but the problem i have is that i need to enter yes in the case of a control panel install. When the installer is running i am asked if i would like to continue. How do i do that? That is the problem i am having. – carlosx2 Apr 01 '15 at 12:36
  • If the command you need to run is `panel-install` (replace it by your command, of course), use `echo 'yes' | panel-install`. This will basically run the command, and place "yes[enter" in its standard input, just like if you wrote 'yes' from your keyboard. – christophetd Apr 01 '15 at 12:48
  • wouldn't this become a problem with you other questions where you have to input a number or a name etc. For example i am trying to make a virtualmin control panel bash script. It get input values. But when you run the installer from the command line you get a menu you go through. which asked you several questions that each need a different input and then enter. One of them at the start is if you would like to continue. – carlosx2 Apr 01 '15 at 12:53
  • that is what i need. You really have helped me so much. Really great. Thanks – carlosx2 Apr 01 '15 at 13:34