在格伦的帮助下,我得到了解决方案..我的最终脚本是::
期望脚本是
[Linux Dev:anr ]$ cat testexit.sh #!/bin/bash export tmp_script_file="/home/anr/tmp_script_temp.sh" cp /home/anr/tmp_script $tmp_script_file chmod a+x $tmp_script_file cat $tmp_script_file expect << 'EOF' set timeout -1 spawn $env(tmp_script_file) expect { "INVALID " { exit 4 } timeout { exit 4 } eof } foreach {pid spawnid os_error_flag value} [wait] break if {$os_error_flag == 0} { puts "exit status: $value" exit $value } else { puts "errno: $value" exit $value } EOF echo "spawned process status" $? rm -f $tmp_script_file echo "done"产生的脚本:
[Linux Dev:anr ]$ cat tmp_script exit 3
执行Expect脚本:
[Linux Dev:anr ]$ ./testexit.sh exit 3 spawn /home/anr/tmp_script_temp.sh exit status: 3 spawned process status 3 done
再次感谢格伦..



