FrancoVP
FrancoVP

Reputation: 335

Can't run an expect script: invalid command name "Yes/No"

I have this expect script that need to execute some other shell script to accept a Licence agreement

#!/usr/bin/expect
spawn ./xxx.sh
expect -ex "--More--"
send -- " "
expect "Do you agree with this license ?[Yes/No]"
send "Y\r"

But when I run it I get this error

invalid command name "Yes/No"
while executing
"Yes/No"
invoked from within
"expect "Do you agree with this license ?[Yes/No]""
(file "./xxx.sh" line 5)

I don't know what I'm doing wrong

Upvotes: 2

Views: 2508

Answers (1)

glenn jackman
glenn jackman

Reputation: 246774

expect is an extension of the Tcl language. In Tcl, you use square brackets for command substitution. Like the bash shell, command substitution occurs within double quoted strings.

To prevent your code from attempting to execute the Yes/No command:

  1. use different quotes: Tcl uses curly braces as the non-interpolating quotes:

    expect {Do you agree with this license ?[Yes/No]}
    
  2. escape the brackets to prevent command substitution:

    expect "Do you agree with this license ?\[Yes/No\]"
    

Upvotes: 4

Related Questions