Skip to Content
Exploring Expect
book

Exploring Expect

by Don Libes
December 1994
Intermediate to advanced
606 pages
16h 7m
English
O'Reilly Media, Inc.
Content preview from Exploring Expect

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]

% script

This 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

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Learning Go

Learning Go

Jon Bodner
Command-Line Rust

Command-Line Rust

Ken Youens-Clark
Hands-on Ansible

Hands-on Ansible

Sander van Vugt

Publisher Resources

ISBN: 9781565920903Errata Page