LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 06-16-2010, 11:03 AM   #1
deadeyes
Member
 
Registered: Aug 2006
Posts: 605

Rep: Reputation: 78
expect: line seems to match exactly, however expect thinks not


Hi all,

I am writing an expect script.

At a certain point there is a rule that produces this debugging output:
Code:
expect: does "\r\nAddress or name of remote host [x.x.x.x]? " (spawn_id exp8) match glob pattern "\r\nAddress or name of remote host [x.x.x.x]? "? no
This just times out :s

When I use -exact for the expect keyword it does work :s
What am I doing wrong? THe first should also match in my opinion because it is equal as well. Even if I remove the \r\n I still have the same issue if I try without -exact.

I don't understand. I tried removing the \r\n but still got the same.

Anyone an idea on what the issue might be?

Last edited by deadeyes; 06-16-2010 at 11:06 AM.
 
Old 06-16-2010, 11:51 AM   #2
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 96
Hi.

TCL's and expect's glob patterns use [] for ranges, so it's probably the '[x.x.x.x]' that's tripping it up. Try matching \[x.x.x.x] or \\[x.x.x.x] instead. The '?' should be escaped as well, but since it's the wildcard for any single character, it shouldn't be causing the problem you're seeing.

Dave
 
Old 06-16-2010, 03:30 PM   #3
deadeyes
Member
 
Registered: Aug 2006
Posts: 605

Original Poster
Rep: Reputation: 78
Thanks for your quick response.

I have this in the expect file:
Code:
expect {
      "\r\nAddress or name of remote host \[[lindex $argv 3]\]? " { send -- "\r"; exp_continue }
      ...
}
So these are already escaped.

Edit:
I also tried using:
set myvar [lindex $argv 3]
and then use $myvar in the line but that results in the same issue.

Last edited by deadeyes; 06-16-2010 at 03:57 PM.
 
Old 06-16-2010, 05:25 PM   #4
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 96
Ah, the layers of indirection.

Believe it or not, triple-escaping the first [ should do the job
Code:
expect {
      "\r\nAddress or name of remote host \\\[[lindex $argv 3]\]? " { send -- "\r"; exp_continue }
      ...
}
Dave
 
1 members found this post helpful.
Old 06-16-2010, 05:54 PM   #5
deadeyes
Member
 
Registered: Aug 2006
Posts: 605

Original Poster
Rep: Reputation: 78
Lol... that fixed it indeed!

However I wonder why. \\ seems logical. \\\ doesn't Maybe there are two passes of the part between quotes but that does not explain why the closing ] does not need this.

THanks alot for helping me out!
 
Old 06-16-2010, 06:05 PM   #6
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 96
There are indeed two passes. expect eats one of the \'s, then tcl eats the second \ before the string is used as a glob. The second ] doesn't actually need /any/ escape for this to work, though - feel free to remove it.

Dave
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Expect script: how do i send function key F12 in an expect script alix123 Programming 4 09-01-2013 09:06 PM
Calling expect scripts from other expect scripts sevapopov Linux - Software 3 04-03-2008 09:33 PM
LXer: Command line automation with Expect-lite LXer Syndicated Linux News 0 03-10-2008 05:20 PM
expect debugger quits after one line Hewson Programming 0 05-11-2007 07:48 PM
expect - any other way? rooksin Programming 1 03-09-2006 10:26 PM


All times are GMT -5. The time now is 01:45 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration