Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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" }"
share|improve this question

1 Answer 1

up vote 1 down vote accepted

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}
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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