I'm rather new to expect (and TCL), but not new to programming. However I'm fighting a problem I cannot solve (using expect 5.45):
I want to match (expect
) a string like [detached from ...]
, but I did not succeed:
-gl "\[detached from *\]"
is treated as a character class, matching single characters repeatedly.
-gl "\\[detached from *\\]"
seems to be identical to -gl "[detached from *]"
, causing an error like "invalid command name "detached"".
Obviously I cannot use -ex(act)
as the ...
part is variable.
Because of the double quotes, you need:
expect -gl "\\\[detached from *\\\]"
The first 2 slashes are to put a literal slash in the pattern.
The 3rd slash is to escape the bracket from being interpreted as command substitution.
Simpler though would be to use braces (Tcl's equivalent of the shell single quotes
expect -gl {\[detached from *\]}