0

I'm trying to write an expect script that calls a bash script that may or may not output a line of text:

...
expect "this string appears"
...
expect "this string may or may not appear"
...
expect "this string appears"
...

How do I code in expect to send something if "this string may or may not appear" appears, or move on if it doesn't?

Evan Baldonado
  • 348
  • 1
  • 2
  • 13

1 Answers1

0

You would use a multi-pattern expect statement:

expect {
    "this string may or may not appear" {
        # do stuff ...
        exp_continue
    }
    "this string appears"
}
# ... do more stuff

The exp_continue command essentially "loops" within the expect command so it can continue to look for any of the given patterns. The last pattern "this string appears" has no action block, so the expect command returns and the script carries on with the next command.

glenn jackman
  • 238,783
  • 38
  • 220
  • 352