我正在尝试将tcl缓冲区导出为bash变量,我无法让它工作。
我希望下面的例子能清楚我想要完成的事情。
我肯定想要一个tcl嵌入脚本
======================================
#!/bin/bash
var=bash_to_tcl
expect -c "
puts lindex $argv 0
expect "xx"
send "123\n"
set $var $expect_out(buffer) <<<< setting the variable to export to bash>>>>>>
}
exit 0
&LT;&LT;&LT;&GT;&GT; =====================================
echo $var "tcl_to_bash" (THIS IS WHERE I AM HAVING ISSUES) <<<<<<<<<<<<<<<<<<<
=====================================
我一直在寻找一些例子的线索,但找不到任何。 我让ecpect工作,但无法将输出输出回bash
答案 0 :(得分:3)
子进程(期望)不能改变父进程(bash)的环境。通常,信息通过stdio通道在进程之间传递:
#!/bin/bash
# this is how bash captures the output of the expect program
var=$(expect -c '
spawn ...
expect "xx"
send "123\n"
# here is expect sending the info back to the parent
puts $expect_out(buffer)
')
do something with "$var"