O'Reilly logo

Exploring Expect by Don Libes

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Example—The Return Value From A Remote Shell

While I have shown some fairly complex patterns, real patterns are usually pretty simple. In fact, sometimes other issues can make the patterns seem like the easy part of writing scripts.

The rsh program executes a command on a remote host. For example, the following command executes the command "quack twice" on host duck.

% rsh duck quack twice

While quack is a mythical program, you can imagine it shares a trait common to many programs. Namely, quack reports its status by returning an exit value. If quack works correctly, it exits with the value 0 (which by convention means success). Otherwise it exits with the value 1 (failure). From the C-shell, the status of the last command is stored in the variable status. I can demonstrate a successful interactive invocation by interacting directly with the C-shell.

% quack twice
% echo $status
0

Unfortunately, if quack is executed via rsh, the same echo command will not provide the exit status of quack. In fact, rsh does not provide any way of returning the status of a command. Checking the value of status after running rsh tells you only whether rsh itself ran successfully. The status of rsh is not really that useful. It reports problems such as "unknown host" if you give it a bogus host. But if rsh locates the host and executes the command, that is considered a success and 0 is returned no matter what happens inside the command. In fact, the rsh is considered a success even if the command is not ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required