Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expect script arrow keys

I didn't know that how to send arrow keys using expect, hence I generated autoexpect script for all the arrow keys and found out that autoexpect generates this character for right arrow key:

send -- "^[\[C"

I used the same send command in my custom script and I'm getting a following error:

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

What exactly shall I do to send the right arrow key. Any help would be appreciated.

like image 600
Aaron88 Avatar asked Jun 01 '26 21:06

Aaron88


1 Answers

"^[\[C" is an invalid string in Tcl. ^[ should be the ESC char which is \033. So try this:

send "\033\[C"

UPDATE:

The safest way to get the correct RIGHT ARROW key for current terminal (as in $TERM) is to use tput:

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

To know what cuf1 means, run man terminfo and search for it. :)

like image 159
pynexj Avatar answered Jun 04 '26 13:06

pynexj