What Happens To Things That Do Not Match
As characters are entered, they are compared to the patterns. Characters that do not match any of the patterns are sent to the spawned process. This includes characters before and after any matches. Any characters involved in a match are not sent to the spawned process. Consider the following interact
command, which sends "hugs and kisses
" if it sees XOX
.
interact "XOX" {send "hugs and kisses"}
If the user types AXOXB
, the spawned program receives "Ahugs and kissesB
“. The A
does not match so it is sent literally. The XOX
is replaced by the phrase "hugs and kisses
“. And the trailing B
does not match so it is sent literally.
If the user types AXOYB
, the spawned program receives AXOYB
. The pattern XOX
cannot match any part of what was entered, so it is all sent on.
If the user types XOXO
, the spawned program receives "hugs and kissesO
“. The first XOX
matches so it is translated and sent on, but the O
that remains cannot possibly match XOX
so it is sent literally.
If the user types XOXOX
, the spawned program receives "hugs and kissesO
" following the logic of the previous case. The trailing X
can match the pattern XOX
if another OX
is entered so the interact
command waits for more characters to be entered before deciding whether to send on the X
or not. Suppose the user instead enters Z
. In this case, the X
can no longer match so interact
sends the string XZ
to the spawned process. What would have happened if the user entered another X
rather than ...
Get Exploring Expect now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.