Skip to main content
deleted 45 characters in body
Source Link
l0b0
  • 53.6k
  • 48
  • 225
  • 398

Q1: I'm not entirely sure what you mean by that. I'm not an expect user, but it seems clear that spawn runs a script in the background and makes it controllable by expect, rather than just running without any interactivity.

Q2: The string is passed as a script to expect. I assume, like most scripting languages, this is equivalent to saving the string to a file and running expect file.

Q3: It looks like a test to see that myscript.sh, when run, prints a message and responds to a user provided value by exiting without printing anything.

In other words, I expect (hur, hur) you should be able to run this directlyscript with the same result:

#!/usr/bin/expect
spawn myscript.sh arg1 arg2 # Run `myscript.sh arg1 arg2` and return control to `expect`
expect "Please enter your value: " # Succeeds if the script prints this value
send "myval\r" # Simulate entering this value
expect eof # Succeeds if the script ends without printing anything

Q1: I'm not entirely sure what you mean by that. I'm not an expect user, but it seems clear that spawn runs a script in the background and makes it controllable by expect, rather than just running without any interactivity.

Q2: The string is passed as a script to expect. I assume, like most scripting languages, this is equivalent to saving the string to a file and running expect file.

Q3: It looks like a test to see that myscript.sh, when run, prints a message and responds to a user provided value by exiting without printing anything.

In other words, I expect (hur, hur) you should be able to run this directly:

#!/usr/bin/expect
spawn myscript.sh arg1 arg2 # Run `myscript.sh arg1 arg2` and return control to `expect`
expect "Please enter your value: " # Succeeds if the script prints this value
send "myval\r" # Simulate entering this value
expect eof # Succeeds if the script ends without printing anything

Q1: I'm not an expect user, but it seems clear that spawn runs a script in the background and makes it controllable by expect, rather than just running without any interactivity.

Q2: The string is passed as a script to expect. I assume, like most scripting languages, this is equivalent to saving the string to a file and running expect file.

Q3: It looks like a test to see that myscript.sh, when run, prints a message and responds to a user provided value by exiting without printing anything.

In other words, I expect you should be able to run this script with the same result:

#!/usr/bin/expect
spawn myscript.sh arg1 arg2 # Run `myscript.sh arg1 arg2` and return control to `expect`
expect "Please enter your value: " # Succeeds if the script prints this value
send "myval\r" # Simulate entering this value
expect eof # Succeeds if the script ends without printing anything
Source Link
l0b0
  • 53.6k
  • 48
  • 225
  • 398

Q1: I'm not entirely sure what you mean by that. I'm not an expect user, but it seems clear that spawn runs a script in the background and makes it controllable by expect, rather than just running without any interactivity.

Q2: The string is passed as a script to expect. I assume, like most scripting languages, this is equivalent to saving the string to a file and running expect file.

Q3: It looks like a test to see that myscript.sh, when run, prints a message and responds to a user provided value by exiting without printing anything.

In other words, I expect (hur, hur) you should be able to run this directly:

#!/usr/bin/expect
spawn myscript.sh arg1 arg2 # Run `myscript.sh arg1 arg2` and return control to `expect`
expect "Please enter your value: " # Succeeds if the script prints this value
send "myval\r" # Simulate entering this value
expect eof # Succeeds if the script ends without printing anything