The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-19-2008
voorkey voorkey is offline
Registered User
  
 

Join Date: May 2006
Posts: 6
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
  #2 (permalink)  
Old 02-19-2008
sysgate's Avatar
sysgate sysgate is offline Forum Advisor  
Unix based
  
 

Join Date: Nov 2006
Location: Bulgaria
Posts: 1,318
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");
The error you got is most probably related to un-escaped symbols, missing quotes, etc.
Or if you want to use the backthicks, put "" around them.

Last edited by sysgate; 02-19-2008 at 10:06 AM..
  #3 (permalink)  
Old 02-19-2008
voorkey voorkey is offline
Registered User
  
 

Join Date: May 2006
Posts: 6
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 (permalink)  
Old 02-19-2008
KevinADC KevinADC is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2008
Posts: 731
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;
  #5 (permalink)  
Old 03-30-2009
chethanmurari chethanmurari is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 1
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.
  #6 (permalink)  
Old 03-30-2009
pludi's Avatar
pludi pludi is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2008
Location: .at
Posts: 1,837
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 .
If you get anything but "is a shell builtin" or "not found", I'd be very surprised.

Try running it as
Code:
system("/usr/bin/ksh set_file");
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:49 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0