Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 10-07-2010, 09:40 AM   #1
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:

#!/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 -
Old 10-07-2010, 10:12 AM   #2
Senior Member
Registered: Jan 2010
Posts: 1,620

Rep: Reputation: 451Reputation: 451Reputation: 451Reputation: 451Reputation: 451

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

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 10:23 AM.


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

All times are GMT -5. The time now is 04:40 AM.

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