0

我正在尝试将 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

<<<>> =======================================

echo $var "tcl_to_bash"    (THIS IS WHERE I AM HAVING ISSUES) <<<<<<<<<<<<<<<<<<<
=====================================

我一直在寻找一些示例线索,但找不到任何线索。我让 ecpect 正常工作,但无法将输出导出回 bash

4

1 回答 1

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"
于 2013-10-30T15:37:18.567 回答