![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Perl Script Error with find command | MKNENI | Shell Programming and Scripting | 4 | 03-26-2008 09:02 AM |
| mv command is giving error in shell script | gammit | Shell Programming and Scripting | 5 | 12-13-2007 12:56 AM |
| Error message while executing the shell script | ajayyaduwanshi | Shell Programming and Scripting | 4 | 10-25-2007 04:12 AM |
| perl - why is the shell script executed before the print command? | mjays | Shell Programming and Scripting | 3 | 09-21-2007 02:49 AM |
| perl command help in shell script | venky_2_2000 | Shell Programming and Scripting | 2 | 09-06-2005 02:20 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Error executing shell command from a perl script
Hi Gurus,
I've a find command that gets the list of files from a source directory where the extension is not html, xml, jsp, shtml or htaccess. The below find command runs fine from the command prompt or in a shell script. I need to eventually run it in a PERL script and am getting the following error when run from perl script. `find <Source-dir-path> ! \( -name '*.html' -o -name '*.xml' -o -name '*.jsp' -o -name '*.shtml' -o -name '*.htaccess' \) -type f -print`; sh: syntax error at line 1 : `(' unexpected Running out of fuel and would appreciate any help or suggestions to make this work. Thanks |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
try using :
Code:
system ("find <Source-dir-path> ! \( -name '*.html' -o -name '*.xml' -o -name '*.jsp' -o -name '*.shtml' -o -name '*.htaccess' \) -type f -print");
Or if you want to use the backthicks, put "" around them. Last edited by sysgate; 02-19-2008 at 07:06 AM. |
|
#3
|
|||
|
|||
|
Thanks for your response. I tried using system ("find <Source-dir-path> ! \( -name '*.html' -o -name '*.xml' -o -name '*.jsp' -o -name '*.shtml' -o -name '*.htaccess' \) -type f -print"); but that reported the same syntax error. I noticed that perl was eliminating the '\', so to get over the issue I used '\\' like indicated below and it worked like charm
`find <Source-dir-path> ! \\( -name '*.html' -o -name '*.xml' -o -name '*.jsp' -o -name '*.shtml' -o -name '*.htaccess' \\) -type f -print`; |
|
#4
|
|||
|
|||
|
Perl has a module used for this purpose File::Find which should be more efficient than shelling out to the find command. It is also easy enough to code if you don't need to search sub directories
Code:
opendir (DIR,'path/to/folder') or die "$!";
my @files = grep {-f "path/to/folfer/$_" && !/\.html$|\.xml$|\.jsp$|\.shtml$|\.htaccess$/} readdir DIR;
close DIR;
print "$_\n" for @files;
|
|||
| Google The UNIX and Linux Forums |