简体   繁体   English

使用 Bash 脚本将输入提供给命令行

[英]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.所以我正在尝试制作一个 bash 脚本来调用这个命令,然后将输入提供给它。 It calls this one command and the command needs 3-4 inputs after.它调用这一个命令,该命令之后需要 3-4 个输入。 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?如何使用 bash 脚本一次将这些参数传递给命令?

A couple of ways.几种方式。

Group all the echo commands and pipe them to the command:将所有 echo 命令分组并将它们通过管道传输到命令:

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

or use a heredoc:或使用heredoc:

somecommand <<EOF
$firstname
$lastname
EOF

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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