期待脚本箭头键

时间:2014-12-16 01:30:53

标签: networking tcl expect system-administration

我不知道如何使用expect发送箭头键,因此我为所有箭头键生成了autoexpect脚本,并发现autoexpect为右箭头键生成了这个字符:

send -- "^[\[C"

我在自定义脚本中使用了相同的send命令,但我收到了以下错误:

while executing
"send -- "^[\[C"
expect eof
"
    (file "script_auto.exp" line 38)

我该怎样做才能发送右箭头键。任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:3)

"^[\[C"Tcl中的无效字符串。 ^[应该是ESC字符\033。所以试试这个:

send "\033\[C"

<强>更新:

获取当前终端的正确右箭头键的最安全方法(如$TERM)是使用tput

[bash] # v=$(tput cuf1)
[bash] # printf '%q\n' "$v"
$'\E[C'
[bash] #

要了解cuf1的含义,请搜索terminfo的手册页。 :)

答案 1 :(得分:0)

对于上箭头键,您必须按如下所示发送

send "\033\[A"

我已经测试过