Reputation: 214
I have looked in the Expect manpage and Googled it, but I have not found what the -r
for expect is. I saw this option used before like this
expect -r "\r\n\r\n"
in an expect
script, but can't figure out what it's for. Does anyone know where I can look to find this answer? Thanks in advance
Upvotes: 0
Views: 729
Reputation: 20698
This also confused me a bit when I saw someone was using expect -regexp PATTERN
because in the man page it only mentions expect -re PATTERN
. I tried expect -regexp PATTERN
and it indeed works.
At some time I downloaded Expect's source code and took a look and found out the reason.
In the source code (see the function parse_expect_args()
in expect.c
), the expect
's options are actually defined as follows:
static char *flags[] = {
"-glob", "-regexp", "-exact", "-notransfer", "-nocase",
"-i", "-indices", "-iread", "-timestamp", "-timeout",
"-nobrace", "--", (char *)0
};
then in the function it calls Tcl's Tcl_GetIndexFromObj(interp, objPtr, tablePtr, msg, flags, indexPtr)
to parse command options. Accordint to Tcl_GetIndexFromObj()
's manual:
... a match occurs if
objPtr
's string value is identical to one of the strings intablePtr
, or if it is a non-empty unique abbreviation for exactly one of the strings intablePtr
and theTCL_EXACT
flag was not specified; ...
Here Expect
calls Tcl_GetIndexFromObj()
with flags = 0
(no TCL_EXACT
) so the documented -gl
, -re
and -ex
in the man page are actually -glob
, -regexp
and -exact
respectively. And since there's only one option -regexp
starting with -r
so -r
just means the same as -regexp
(and -re
).
Personally I recommend the documented options still be used to avoid confusing other people.
Upvotes: 5