【问题标题】:How to execute custom command in bash script如何在 bash 脚本中执行自定义命令
【发布时间】:2016-03-11 04:24:17
【问题描述】:
我想构建一个这样的脚本:
#!/bin/bash
/path/to/my/program/myProgram
MyCommand1 < — This is NOT a bash command
MyCommand2 < — Neither is it
这些命令只有我的程序的某种交互式会话才能接受。任何想法我该怎么做?
【问题讨论】:
标签:
linux
bash
shell
terminal
sh
【解决方案1】:
echo -e "MyCommand1\nMyCommand2"| /path/to/my/program/myProgram
或
/path/to/my/program/myProgram << EOF
MyCommand1
MyCommand2
EOF
如果您想延迟输入,请尝试以下操作:
(sleep 2; echo "MyCommand1"; sleep 1; echo "MyCommand2") | /path/to/my/program/myProgram