Automate enter input on command line while executing a bash script

3

I created a bash script to automate the installation and configuration of my environment needed to run my project, but some of the tasks require that the actions be confirmed by entering enter, I would like to know how I can automate this input (from an ENTER) in the script so that it can be run completely without any human interaction.

    
asked by anonymous 01.11.2016 / 18:24

1 answer

2

You can do:

echo | [o seu comando que necessita de input]

An example. Imagine that you have a directory called OMeuDirectorio and you want to delete it with rm OMeuDirectorio -ri (note the i so that rm is executed interactively).

To do it automated, you could do the following:

echo 'y' | rm OMeuDirectorio -ri

The y character is passed to the stdinput and is consumed by the next time a user interaction is required.

In your case, as one of your commands will require a Enter , just invoke the command as above (pass echo per pipeline to your command).

(Note that echo produces a new line (a Enter ) by default).

    
01.11.2016 / 18:30