期望不匹配 glob 模式

Expect not matching glob pattern

我编写了一个脚本来自动执行登录过程,下面是我遇到问题的部分代码。

spawn globalprotect connect --portal vpnconnect.myserver.com
expect { "1234myuser*:" } {
    send -- "\r"
}

运行时globalprotect connect --portal vpnconnect.myserver.com终端输出的提示如下:

Retrieving configuration...                                            
vpnconnect.manchester.ac.uk - Enter login credentials
username(1234myuser):

在这个阶段我需要输入一个换行符(因此 send -- "\r"),但是 glob 模式 "1234myuser*:" 与这个序列不匹配。下面是 运行 expect -d ./myscript.sh

的输出
expect version 5.45.4
argv[0] = expect  argv[1] = -d  argv[2] = ./myscript.sh 
set argc 0
set argv0 "./myscript.sh"
set argv ""
executing commands from command file .manvpn.sh
spawn globalprotect connect --portal vpnconnect.myserver.com
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {141688}

expect: does "" (spawn_id exp4) match glob pattern "1234myuser*:" "? no
Retrieving configuration...                                            

expect: does "\r                                                                       \rRetrieving configuration...\r\n" (spawn_id exp4) match glob pattern "1234myuser*:" "? no
vpnconnect.myserver.com - Enter login credentials
username(1234myuser):
expect: does "\r                                                                       \rRetrieving configuration...\r\nvpnconnect.myserver.com - Enter login credentials\r\nusername(1234myuser):" (spawn_id exp4) match glob pattern "1234myuser*:" "? no
expect: timed out

N.B 我的用户名显然不是 1234myuser,而是类似的一系列字母数字字符。

N.B 我也尝试过类似的 glob 模式,例如 *(1234myuser):""*1234myuser*" 无济于事。

Expect 使用 Tcl 并且在 Tcl 中 { "1234myuser*:" }" \"1234myuser*:\" " 相同。

你应该写:

expect "1234myuser*:" {
    send -- "\r"
}