No glob expansion without -re option in Expect

2019-08-13 00:22发布

#!/usr/bin/expect

spawn passwd [lindex $argv 0]
set password [lindex $argv 1]

expect -nocase "pass*" {
      send "$password\r"
}

expect -nocase "password" {
      send "$password\r"
}

expect eof

How can I prevent expect to expand the glob * in pass*? This is just an example. In my actual code, I want to keep the glob, but I don't want to at -ex, which stands for exact match, or -re option for regex.

标签: tcl expect
2条回答
男人必须洒脱
2楼-- · 2019-08-13 00:37

If you want a glob-style match, use the -gl option before it:

expect {
    -gl -nocase "pass*" {
        # Do something...
    }
}
查看更多
不美不萌又怎样
3楼-- · 2019-08-13 01:02

As you wrote to prevent from globing of * use -ex. By default -gl is assumed. Or use -re and escape * as: \\*.

查看更多
登录 后发表回答