将输入传递给 bash 中的交互式命令行程序

Tim*_*Tim 6 linux bash shell echo cat

我有一个有自己提示的程序

example_program>
Run Code Online (Sandbox Code Playgroud)

我需要通过这个程序运行一系列命令

example_program> command_A
example_program> command B
Please enter input: [input_here]
example_program> command C
Run Code Online (Sandbox Code Playgroud)

我可以通过 shell 脚本中的以下行发送命令 A、B、C:

(echo "command_C" && cat) | (echo "command_B" && cat) | (echo "command_A" && cat ) | example_program
Run Code Online (Sandbox Code Playgroud)

如何输入所需的输入并在命令 B ([input_here]) 后提示输入?

我无权发送或期待。

gle*_*man 4

我猜这会起作用,但这只是猜测,因为我们不知道您的程序如何读取响应:使用此处文档,并在调用命令 B 后输入命令 B

example_program <<'END'
command_A
command B
input_here
command C
END
Run Code Online (Sandbox Code Playgroud)