The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Calling expect scripts from other expect scripts seva Shell Programming and Scripting 0 04-03-2008 10:45 AM
tcl/expect calsum Shell Programming and Scripting 7 03-25-2008 10:23 PM
Expect/Tcl help? earnstaf UNIX for Dummies Questions & Answers 2 07-26-2007 07:01 AM
Expect and auto expect command arun_v Shell Programming and Scripting 0 03-29-2006 04:31 AM
Expect with tcl/tk sanjustudy Shell Programming and Scripting 0 10-10-2005 02:48 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 11-06-2007
Registered User
 

Join Date: Nov 2007
Posts: 4
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
Reply With Quote
Forum Sponsor
  #2  
Old 11-07-2007
Registered User
 

Join Date: Nov 2007
Posts: 32
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
Reply With Quote
  #3  
Old 11-07-2007
Registered User
 

Join Date: Nov 2007
Posts: 4
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
Reply With Quote
  #4  
Old 11-07-2007
Registered User
 

Join Date: Nov 2007
Posts: 4
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
Reply With Quote
  #5  
Old 11-08-2007
Registered User
 

Join Date: Nov 2007
Posts: 32
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:
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:
Code:
blabla
\[
blabla
but i get
blabla
\\\[
blabla
And I get output like below:
Code:
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.
Reply With Quote
  #6  
Old 11-14-2007
Registered User
 

Join Date: Nov 2007
Posts: 4
thanks! that makes sense.

sorry for the slow reply. was out of town unexpectedly.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 09:25 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0