![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | 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 and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Perl Script Error with find command | MKNENI | Shell Programming and Scripting | 4 | 03-26-2008 12:02 PM |
| mv command is giving error in shell script | gammit | Shell Programming and Scripting | 5 | 12-13-2007 03:56 AM |
| Error message while executing the shell script | ajayyaduwanshi | Shell Programming and Scripting | 4 | 10-25-2007 07:12 AM |
| perl - why is the shell script executed before the print command? | mjays | Shell Programming and Scripting | 3 | 09-21-2007 05:49 AM |
| perl command help in shell script | venky_2_2000 | Shell Programming and Scripting | 2 | 09-06-2005 05:20 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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 |
|
||||
|
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`; |
|
||||
|
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;
|
|
||||
|
System command in perl
i too have some problem with command source..
system("source set_file"); if ( $? == -1 ) { print "command failed: $!\n"; } else { # printf "command exited with value %d", $? >> 8; print "set\n " ; } After running this. Im getting following error: -1 command failed: No such file or directory it giving error although the file exists. can somebody help me how to operate source command using system function in perl. |
|
|||||
|
source isn't a system command, but a shell-internal, telling it to read the given script in the current shells context. To check this, at the command prompt enter
Code:
$ which source $ type source $ type . Try running it as Code:
system("/usr/bin/ksh set_file");
|
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|