Johsh Hanks
Johsh Hanks

Reputation: 147

Using Bash Script to feed input to command line

So I am trying to make a bash script that calls this one command and then feeds it the input. It calls this one command and the command needs 3-4 inputs after. I type the command and it waits for me to enter first name, one I enter first name it waits for me to enter last name, and so on. How can I use bash script to pass these arguments to the command one at a time?

Upvotes: 5

Views: 16014

Answers (1)

Barmar
Barmar

Reputation: 782295

A couple of ways.

Group all the echo commands and pipe them to the command:

{ echo $firstname; echo $lastname ; } | somecommand

or use a heredoc:

somecommand <<EOF
$firstname
$lastname
EOF

Upvotes: 18

Related Questions