LinuxAnswers - the LQ Linux tutorial section.
Go Back > Forums > Linux Forums > Linux - Software
User Name
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.


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

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.


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
Senior Member
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
dunno perl, but

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
Registered: Aug 2003
Location: Spain
Distribution: Ubuntu
Posts: 893

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
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.7, Centos 5.10
Posts: 16,917

Rep: Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214
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


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 04:57 PM.

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