0

please advice what's wrong with my exepct syntax ( I run expect in ksh script on Solaris 10 machine )

I want to verify if OS is linux

so if it true the expect check if prompt is "#" or ">"

and then run the "ls" command

but I get the error below please advice what could be the problem

     OS=solaris

     expect_do_something=`cat << EOF
     set timeout -1
     spawn   telnet 0 $IP_ADDRESS
     expect login:           {send $LOGIN\r}
     expect Password:        {send "$PASS\r"}




 if { "$OS" == "solaris" }
    {
      expect -re {#|>}        {send ls\r}
    }

 expect eof
 EOF`

 expect -c  "$expect_do_something"

the error from expect:

  wrong # args: no script following " "solaris" == "solaris" " argument
     while executing
  "if { "solaris" == "solaris" }"

1 Answer 1

1

Expect, being an extension of Tcl, has to respect Tcl's very few syntax rules. In Tcl, a newline signifies the end of the command (see this rule), so you must put the open brace of the if-body on the same line.

if { "$OS" == "solaris" } {
  # ......................^
  expect -re {#|>} {send ls\r}
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .