Automate enter input in command line while running a bash script

Asked

Viewed 1,339 times

3

I created a script in bash to automate the installation and configuration of my environment necessary to run my project, but some of the tasks require that the actions are confirmed giving enter, I wonder how I can automate this input (from a ENTER) in the script so that it can be run completely without any human interaction.

1 answer

2


Can do:

echo | [o seu comando que necessita de input]

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

To do it in an automated way, you could do the following:

echo 'y' | rm OMeuDirectorio -ri

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

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

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

  • I did not understand, in case my command that is requesting input, should precede echo | would be this?

  • 1

    Understood, I accepted the reply, thank you @Omni

Browser other questions tagged

You are not signed in. Login or sign up in order to post.