Welcome to the most active Linux Forum on the web.
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, 10:36 AM   #1
Registered: Aug 2003
Location: Spain
Distribution: Ubuntu
Posts: 895

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, 10: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 10:45 AM.
Old 02-25-2008, 12:16 PM   #3
Registered: Aug 2003
Location: Spain
Distribution: Ubuntu
Posts: 895

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, 06:46 PM   #4
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,374

Rep: Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383
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 07:30 PM
Run script on every file contained within a parent directory and its subdirectories General Programming 4 05-15-2006 02:12 AM
Bash script - executing a script through subdirectories bubkus_jones Programming 5 04-24-2006 05:05 PM
executing a script in multiple subdirectories jerryfreak Linux - Newbie 1 04-19-2005 08:34 PM
Script For Moving Files In Subdirectories darkmage Linux - General 3 12-17-2002 06:34 PM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:58 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