expect: \\\[

hi all. i have a little problem:

i read the following from a file with gets

blabla;\\\[;blabla2

my script:

snip

while {[gets $input line] >= 0} {
set y 0
puts $logfile "line = $line"
foreach cel [split $line ";"] {
set filedata($x,$y) $cel
incr y
puts $logfile $cel
}
incr x
}

snip

now when i puts the cells i expect

blabla
\[
blabla

but i get

blabla
\\\[
blabla

when i do puts "\\\[" directly i get \[
also when i do set mytest "\\\["; puts $mytest

whats going on?

thanks for the help!
david

It is really very interesting issue.

Can you paste here all your code, especially part when you read input ale place it in variable "input".

From my experience version of expect can play role also.

Regards
Sebastian

try this: make an input.txt with \\\[ and run this script. it expects an argument which it uses for "expect". it then prints the argument, global $myexp and the line read from the file in da.log.

you can take out the send/expect part.

#!/usr/bin/expect -f
#
set logfile [open "da.log" w]
set myarg [lindex $argv 0]

set myexp "\\\["

set filename "input.txt"

set input [open $filename "r"]

gets $input line
puts $logfile "from file: = $line"
close $input

proc do_it { exp } {

global logfile

puts $logfile "do_it: expecting $exp"
send -- "ls\\r"
expect \{
    timeout \{ puts "timed out!!" \}
    $exp
\}

}

puts $logfile "myexp:$myexp and argument:$myarg"
set timeout 5

spawn $env(SHELL)
match_max 100000

do_it $myarg

simplified:

#!/usr/bin/expect -f
#
set myarg [lindex $argv 0]

set myexp "\\\["

set filename "input.txt"

set input [open $filename "r"]

gets $input line
string trim $line "\n"

puts "from file:$line"
puts "myexp:$myexp"
puts "argument:$myarg"
close $input

input.txt:
\\\[

when you run this you get:
$ ./script.exp \\\[
from file:\\\[
myexp:\[
argument:\[

why doesnt it evaluate the \\\[ from the file properly ??? trimmnig the newline char doesnt make a difference

I think that question is not 'why doesn't it evaluate from file properly' but 'why it evaluate content of variable'.

Please look at this code:

#!/usr/local/bin/expect -f
log_file -noappend expect.log
exp_internal 1

set myarg [lindex $argv 0]

set myexp {\\\[}

set filename "input.txt"

set input [open $filename "r"]

gets $input line
string trim $line "\n"

puts "myexp:$myexp"
puts "argument:$myarg"

while {[gets $input line]} {
        puts "from file: = $line"
}
close $input

My input file is:

blabla
\[
blabla
but i get
blabla
\\\[
blabla

And I get output like below:

myexp:\\\[
argument:\[
from file: = \[
from file: = blabla
from file: = but i get
from file: = blabla
from file: = \\\[
from file: = blabla
malyska@prov01$ expect.exp2.sh '\\\['
myexp:\\\[
argument:\\\[
from file: = \[
from file: = blabla
from file: = but i get
from file: = blabla
from file: = \\\[
from file: = blabla

As you see if you use quotation marks expect will evaluate it. If you don't want to do it you have to use {} marks.

Similar with input to script. If you don't use some marks as '' or "" shell will evaluate it before putting it script.

thanks! that makes sense.

sorry for the slow reply. was out of town unexpectedly.