代码: 全选
#!/bin/bash
root .x test.cpp
.q
或另外的例子,想在shell文件里 “用vim 新建一个文件,输入简单字符后保存退出”
感觉把那些命令集成在shell里自动运行方便些,不知怎样才能达到上述的目的?
代码: 全选
#!/bin/bash
root .x test.cpp
.q
首先非常感谢坛友的回复!susbarbatus 写了:不太懂, 这个 root (cern root?) 是个交互式的东西?
建议研究下 expect,用于交互式程序的自动化的。
我试了expectsusbarbatus 写了:不太懂, 这个 root (cern root?) 是个交互式的东西?
建议研究下 expect,用于交互式程序的自动化的。
代码: 全选
#!/usr/bin/expect -f
2 set timeout 30
3 /usr/local/bin/root .x test.cpp
4 expect "(int)0"
5 send ".q"
6 interact
代码: 全选
wesley@wesley-Rev-1-0:~⟫ ./test.sh
invalid command name "/usr/local/bin/root"
while executing
"/usr/local/bin/root .x test.cpp"
(file "./test.sh" line 3)
多谢多谢!!! 改成spawn root .x test.cpp就可以了~~susbarbatus 写了:报这个错是因为这个 root 不是 expect 有效的命令,改成 spawn "root .x test.cpp" 之类的试试看。