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
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
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.