LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 10-07-2010, 08:40 AM   #1
Mikey0727
LQ Newbie
 
Registered: Aug 2010
Posts: 7

Rep: Reputation: 0
Very Basic expect script - What am I missing?


Hi -

I'm sure there is a simple answer to this question - I have a very basic expect script:

Code:
#!/usr/bin/expect -f
spawn pwd
expect -exact "~]#"     # My Prompt
spawn ls
expect -exact "~]#"
spawn rm -f *.ver
expect -exact "~]#"
At the command prompt in the same directory I run:
touch blah.ver (to create a test file)
check with an ls, and clearly the file is there.

If i run the above script, the pwd command runs fine, as does the ls run fine. In fact I see blah.ver in the output of the ls -
yet, the rm command does not delete the file....

if I remove the -f from the script, the rm command reports:
rm: cannot remove '*.ver' No such file or directory

However, if after the script is complete at the prompt I type
rm -f *.ver

It works as expected, and deletes the file -

What am I missing here?
Thanks -
Mike
 
Old 10-07-2010, 09:12 AM   #2
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,604

Rep: Reputation: 446Reputation: 446Reputation: 446Reputation: 446Reputation: 446
Hi,

as it appears, the spawn command cannot interpret '*' as glob. Not sure if it can be made to work without providing the full name.

[EDIT]
Ok,
Code:
here is one possibility:
#!/usr/bin/expect -f
spawn pwd
expect -exact "~]#"     # My Prompt
spawn ls
expect -exact "~]#"
spawn find ./ -maxdepth 1 -name *.ver -exec rm -f \{} \;
expect -exact "~]#"
Note, that spawn cannot interpret globs and neither can the spawned command rm do. 'find', however, can interpret them. Notice that you do not have to escape or quote *.ver in 'find'. But you will have to escape the curly braces. Do NOT quote them! ESCAPE them!

Hope this helps.

Last edited by crts; 10-07-2010 at 09:23 AM.
 
  


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 Off
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
[SOLVED] /usr/bin/expect : Script to check server load using both expect and bash Soji Antony Programming 1 07-27-2010 11:27 PM
is it possible in expect script packets Programming 2 12-14-2009 08:01 PM
Expect script help shriyer Linux - Server 3 07-08-2009 08:42 PM
Expect Script coolest Programming 7 02-16-2009 03:59 PM


All times are GMT -5. The time now is 07:56 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