Skip to content
Advertisement

Linux shell: my `expect` script doesn’t work as expected

I’ve got a simple script like below, read 2 numbers from command line and add them together:

JavaScript

It runs, no problem. Then I wrote an expect script like below:

JavaScript

Seems still it prompts to read from command line, after quite a long time, it ends.

JavaScript

Where did I get wrong? Thanks.

Advertisement

Answer

You have to send the newlines as well, otherwise it will just wait (at least until the default timeout, which I believe is ten seconds).

In addition, expect is not a fan of single quotes for enclosing strings. Like Tcl (from whence it came), it wants either double quotes or braces. This works just fine:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement