Automate command line enter input while running a bash script


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



echo | [o seu comando que necessita de input]

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

To do it automated, you could do the following:

echo 'y' | rm OMeuDirectorio -ri

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

In your case, as one of your commands will need an Enter , just invoke the command as I said above (pipelined echo for your command).

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

Scroll to Top