Understand the purpose of "-f" flag in expect scripts shebang -
shebang of expect scripts often:
#!/usr/bin/expect -f
according expect manual, -f
flag useful when using #! notation, other arguments may supplied on command line. mean #!/usr/bin/expect -f
shebang, expect handles other code in script-file command-file , allows user specify additional commands on command line, e.g. /usr/bin/custom-expect-script.exp -c "debug 0; log_file /tmp/expect_log_file.log"
?
the -f
flag names file read commands, i.e., script. interactively, may seem pointless. if expect script
, assumed meant expect -f script
anyway.
in fact, there no reason ever utilize -f
command line. provided can used #!
line as:
#!/usr/local/bin/expect -f
just --
, when script starts out -f
line , invoked name (without expect
), behaves had entered next command:
% expect -f script args
now can utilize expect flags such -c
, correctly handled. since -f script
looks flag, expect continues looking , finds -c
, interprets flag, too.
% echo.exp -c "set debug 1" foo bar 17
echo.exp
#!/usr/bin/expect -f if { $debug } { puts "debugging on" } else { puts "turned off debugging" } puts $argc lassign $argv x y z puts "$x, $y , $z"
with -f
flag defined, script can executed without expect
terminal
./echo.exp -c "set debug 1" foo bar 17
else, expect
throw error.
the drawback, of course, if want pass flags own script, have utilize --
. example, assume have own flag defined -e
, -zz
:
% echo.exp -- -e -zz -c
-e
, -zz
not flags known expect, must still utilize -- or else expect tell you have used illegal flag.
% echo.exp -e -zz -c expect: illegal alternative -- e
source : exploring expect
expect
No comments:
Post a Comment