这是一个非常简单的例子:
# expect -c "spawn socat -v -,raw,echo=0,nonblock /dev/ttyS0; interact"
expect
执行内联脚本,生成 socat
以连接到 serial
设备。但是,如果我们有一个名为 serial 的 bash
函数(这非常方便)怎么办:
# serial(){ socat -v -,raw,echo=0,nonblock /dev/ttyS0;}
# expect -c "spawn serial; interact"
spawn serial
couldn't execute "serial": no such file or directory
while executing
"spawn serial"
是否可以在没有包装脚本或二进制文件的情况下强制 expect
执行函数?
最佳答案
您可以导出
shell 函数,以便新的spawn
ed shell 可以调用它。例如:
% cat foo.sh
the_func()
{
echo hello world
}
export -f the_func
expect -c "spawn bash -c the_func; interact"
% bash foo.sh
spawn bash -c the_func
hello world
%
关于linux - 可以期望产生一个 bash 函数吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37127538/