LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices



Reply
 
Search this Thread
Old 02-25-2008, 11:36 AM   #1
jimdaworm
Member
 
Registered: Aug 2003
Location: Spain
Distribution: Ubuntu
Posts: 888

Rep: Reputation: 30
How can I run this script on all .sh in all subdirectories?


Hi everyone I know little about perl or bash but need to run this script on all .sh files in all subdirectories.

Any ideas?

I thought maby I could us find to somehow pipe this info to the script but am not sure how to do this.

Quote:
!/usr/bin/perl

die "Usage: $0 < files >\n" unless @ARGV;

for $file (@ARGV)
{
open IN, $file or die "$0: Cannot open $file for input!\n";

my @lines = <IN>;

close IN;
open OUT, "> $file" or die "$0: Cannot open $file for output!\n";

s/\r$// for @lines;
print OUT for @lines;
}
 
Old 02-25-2008, 11:43 AM   #2
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
dunno perl, but

Code:
find PATH/YOU/WANT -name '*sh' -exec your_perl_thing {} +
should do - but it looks like the perl thing just checks to see if a file is readable? You could do that with find alone, using the permissions tests. But I'm probably not following the perl thing.

-- Oh, I meant to note that this assumes all your shell scripts actually end in 'sh'. (Mine don't as a rule.) If you really have shell scripts scattered all over rather than in a particular directory, I guess you'd need to 'file' them, too.

Last edited by slakmagik; 02-25-2008 at 11:45 AM.
 
Old 02-25-2008, 01:16 PM   #3
jimdaworm
Member
 
Registered: Aug 2003
Location: Spain
Distribution: Ubuntu
Posts: 888

Original Poster
Rep: Reputation: 30
Thanks a lot for your help, thats what I was sort of thinking of and it worked
 
Old 02-25-2008, 07:46 PM   #4
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.6, Centos 5.10
Posts: 16,324

Rep: Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041
Looks like you're trying to get rid of MS (DOS) style line endings, in which case the dos2unix util is what you want.
man dos2unix
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ant script: problem excluding subdirectories kpachopoulos Programming 0 12-12-2006 08:30 PM
Run script on every file contained within a parent directory and its subdirectories General Programming 4 05-15-2006 03:12 AM
Bash script - executing a script through subdirectories bubkus_jones Programming 5 04-24-2006 06:05 PM
executing a script in multiple subdirectories jerryfreak Linux - Newbie 1 04-19-2005 09:34 PM
Script For Moving Files In Subdirectories darkmage Linux - General 3 12-17-2002 07:34 PM


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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration