Restrictions On expect Arguments
The expect command allows its arguments to be surrounded by a pair of braces. This behavior was described in Chapter 3 (p. 76) and is used heavily throughout the book. Bracing the argument list is a convenient feature. Without it, you would have to put backslashes at the ends of many lines to keep long expect commands together.
Consider these two forms:
expect \
pat1 act1 \
pat2 act2 \
pat3 act3
expect {
pat1 act1
pat2 act2
pat3 act3
}
Unfortunately, there is one pitfall with the second form. When the second form is used, there is a question whether the list is a list of patterns or just a single pattern. Although unlikely, it is possible that a pattern could really be "\npat1 act1\npat2 act2\npat3 act3\n“. And while this pattern does not visually look like the multiline expect command above, internally the same representation is used for both.
The expect command uses a heuristic to decide whether the argument is a pattern or a list of patterns.[32]The heuristic is almost always correct, but can be fooled by very unusual patterns or indentation. For instance, the pattern in the previous paragraph is misinterpreted as a list of patterns. It simply looks too much like a list of patterns. Fortunately, situations like this almost never arise. Nonetheless, you may need to worry about it, particularly if you are machine-generating your Expect scripts.
In order to force a single argument to be treated as a pattern, use the -gl flag. (The pattern must be a ...