简体   繁体   English

如何在bash脚本中执行自定义命令

[英]How to execute custom command in bash script

I would like to build a script like this: 我想构建一个像这样的脚本:

#!/bin/bash          
/path/to/my/program/myProgram
MyCommand1    < — This is NOT a bash command
MyCommand2    < — Neither is it

Those are commands acceptable only by some sort of interactive session of my program. 这些是我的程序的某种交互式会话只能接受的命令。 Any ideas how do I do that? 有什么想法我该怎么做?

echo -e "MyCommand1\nMyCommand2"| /path/to/my/program/myProgram

or 要么

/path/to/my/program/myProgram << EOF
MyCommand1
MyCommand2
EOF

When you want to have some delay in your input, try this: 如果您想延迟一些输入,请尝试以下操作:

(sleep 2; echo "MyCommand1"; sleep 1; echo "MyCommand2") | /path/to/my/program/myProgram

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

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