简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM