Issues with Expect

Here is a snippet of code that work for me:

expect  "abc" {send_log "abc found" } \
            "def"  {send_log "def found" } \
            "123" {send_log "123 found}

however the following does not and according to the book "Exploring Expect" it should be equivalent:

expect  { "abc" {send_log "abc found" } 
               "def"  {send_log "def found" } 
               "123" {send_log "123 found}
             }

I'm using expect version 5.43.0 and the date on the book is 1996.

Another issue I have that I can not understand why is:

in response to "ls -l file",

"expect "drwx" {send_log "file found"} 

the log file ends up with "file found", however,

"expect "^drwx" {send_log "file found"}

the log file ends up with nada!

Again the book says it should work with the anchor but not for me. To ensure that the d really is the first character in the out put from ls I did "ls -l file | od -C" and the dump shows the d as first with, no leading unprintable characters much less any printable ones!

These may seem like trivial issues but I need to make the processing more complex and understanding what is going on would really help.

Thanks...twk

Why do you have so many quotes, is it because you are trying to write the code in-line in a shell script? This may cause some unexpected behaviour... at the very least you should probably use single quotes to surround the expect code. Probably best would be to implement the expect script in a separate file with a shebang line such as #!/usr/bin/expect -f.