Amumu
Amumu

Reputation: 18572

No glob expansion without -re option in Expect

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

Upvotes: 1

Views: 304

Answers (2)

gavenkoa
gavenkoa

Reputation: 48933

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

Upvotes: 1

Donal Fellows
Donal Fellows

Reputation: 137787

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

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

Upvotes: 2

Related Questions