Menu

#102 expect_out(N,string) should be reset first when matching against new patterns

open
nobody
None
1
2016-12-21
2016-12-20
dearvoid
No

See following example:

expect -c 'spawn sh -c "echo 11 22 33; echo 44"; expect -re "(11) (22) (33)"; expect -re "(44)|(55) (66)"; expect; puts $expect_out(3,string)'

After expect -re "(44)|(55) (66)", the two variables expect_out(2,string) and expect_out(3,string) still have values which are from expect -re "(11) (22) (33)". They should be reset to UNDEFINED, otherwise users would think that the pattern (55) (66) was matched but actually it was (44).

Discussion

  • Don Libes

    Don Libes - 2016-12-20

    You can complain about the design but it's not a bug. That behavior is documented. (Expect book, page 112.) If you want that behavior, use unset between expects.

     
  • dearvoid

    dearvoid - 2016-12-21

    Thanks Don for the quick response. I did not know you are still working on Expect. :)

    I don't have the Expect book but yes my workaround is also unsetting these expect_out(N,string) vars before matching. To me the behavior is counter-intuitive and I don't know what advantage it has. Anyway I think it's better to doc this in the man page at least.

     
  • Don Libes

    Don Libes - 2016-12-21

    It was a choice made for efficiency rather than elegance, sorry. It didn't seem worth unsetting internally since it was rarely important to users, and in the case that it mattered, it was easy for users to do the unset. If it worked the way you want, users would have to test whether the variable was set or embed it in a catch - both heavyweight solutions anyway, so having users call unset explicitly seemed reasonable in that case.

    You're right that it should be documented in the man page. Create a ticket for that! (I don't actually know who is maintaining Expect these days.)

     

Log in to post a comment.