LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Very Basic expect script - What am I missing? (https://www.linuxquestions.org/questions/programming-9/very-basic-expect-script-what-am-i-missing-836745/)

Mikey0727 10-07-2010 08:40 AM

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

crts 10-07-2010 09:12 AM

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.


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