Jassica has asked for the wisdom of the Perl Monks concerning the following question:

Hello guys, I have a perl script that will pass a command to be excuted by a an expect script on the command line. the perl script doest the follwoing :
$theScript ="temp.exp"; $cd = "cd ../../logs/tu/tull"; $cmd = "expect -f '$theScript' '$cd' pwd 'find . -name '*.std*' -o + -name 'ULOG.*' -mtime + 9 -type f -exec rm {} \\;' pwd"; print "$cmd\n"; system($cmd);
every thing get excuted fine in the front of me by the expect script , however , I get the following error :
---------------------------- - Entering SHELL session . - ---------------------------- > cd ../../logs/tu/tull > pwd /logs/tuxedo/tuxbull > find . -name *.std* -o -name ULOG.* -mtime +9 -type f -exec rm {} \ +; pwd find: missing conjunction > pwd /logs/tu/tull
see the problem I think it that , the single qotes I put around *.std* and ULOG.* are not being passed , how can I make sure they will appear on the command line , can some one help , thanks much

Replies are listed 'Best First'.
Re: single quote problem with system() (can't nest ')
by tye (Sage) on Apr 14, 2003 at 19:50 UTC

    You have single-quoted arguments inside of a single-quote argument:

    "expect -f '$theScript' '$cd' pwd 'find . -name '*.std*' -s (^^^^^^^^^^) (^^^) (^^^^^^^^^^^^^^) (^^^
    so the ' before *.std* is the end of one single-quoted string. Since you have no space there, the shell ends up concatenating all of those bits together and trying to match a very long wildcard. The shell likely ends up passing the following arguments to expect:
    0: expect 1: -f 2: $theScript 3: $cd 4: pwd 5: find . -name *.std* -o -name ULOG.* -mtime +9 -type f -exec rm {} +\; 6: pwd
    but only if $theScript and $cd don't contain any ' characters and there were no files that matched the very long wildcard find . -name *.std* -o -name ULOG.* -mtime +9 -type f -exec rm {} ; (since none of the * characters were inside of single quotes as far as the shell was concerned).

    You'd be better off skipping the shell for this:

    system( 'expect', '-f', $theScript, $cd, 'pwd', "find . -name '*.std*' -o -name 'ULOG.*' -mtime +9 -type f -e +xec rm {} ';'", "pwd", );

                    - tye
Re: single quote problem with system()
by Limbic~Region (Chancellor) on Apr 14, 2003 at 23:16 UTC
    Jassica,
    This looks almost identical to your first node. I understand that the help the monks gave you at that time was not what you were looking for. You were concerned with the single quotes and not a different way of doing it. I do however want to point you back to the wisdom of merlyn, which can be found here. It is concerning the precedence of the -o or operator. It is possible this is what you intend to do, or it is possible this is an oversight.

    I also see you are new to the monastery - welcome. Thanks for sticking with us. If you get answers to your questions that you are not expecting - do not hesitate to clarify yourself.

    Cheers - L~R

Re: single quote problem with system()
by tall_man (Parson) on Apr 14, 2003 at 19:29 UTC
    You should use backslashes on the meta characters, like this:
    '\\*.std\\*'