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


     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

 expect -c  "$expect_do_something"

the error from expect:

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

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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.