No glob expansion without -re option in Expect

南楼画角 提交于 2020-01-15 10:45:37

问题


#!/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.


回答1:


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

expect {
    -gl -nocase "pass*" {
        # Do something...
    }
}



回答2:


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



来源:https://stackoverflow.com/questions/9630185/no-glob-expansion-without-re-option-in-expect

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!