Invoking Scripts Without Saying “expect”
On all but the most ancient UNIX systems, it is not necessary to type expect to run an Expect script. Just the script name is necessary. Assuming the script is constructed properly, both of the following commands do the same thing:
%expect script%script
In the first command, the operating system runs Expect which executes the script. In the second case, the operating system has to use some other means of deducing that the script wants to be executed by the Expect interpreter. The system figures this out by reading the first line of the script. The name of the interpreter must appear after the characters #! in the first line. You must specify the complete path for Expect (even if its directory is in your PATH). In this book, I have assumed that Expect is in /usr/local/bin/expect but that may not be true for your system.
#!/usr/local/bin/expect
If you mark the script as executable (using "chmod +x script“), you can run the script without saying expect in front of the script name each time.[37]
% scriptThis is shorthand for explicitly saying "expect script“. I will occasionally explain the shorthand form in terms of the full "expect script" form to help describe how other arguments are handled.
The #! mechanism has one significant drawback. On many systems, the total length of the first line is limited to 32 characters. If you use more than 32 characters, the operating system will not pass them to Expect. Expect will not see them.
A simple way ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access