The pattern passed to expect()
is a regex, not a literal string. So $
matches the end of a string, which can be anywhere because of the way pexpect works.
You can either escape the dollar signs - \$
- or use expect_exact()
, which takes a plain string.