simple shell scripting or perl help

Bob Wills

500+ Posts
I would like to run a program (foobar) on a bsd system on all of the files in a directory without having to type out the name of each file:

e.g.

./foobar /this/directory/firstfile
./foobar /this/directory/secondfile
./foobar /this/directory/thirdfile
./foobar /this/directory/[...]
./foobar /this/directory/lastfile

Any recommendations?
 
try this...

takes one argument, the directory you want to process

#!/usr/bin/perl

my $dir = shift;

my @files = `/bin/ls -1A $dir`;

if ( $#files < 0 ) {
exit 1;
}

foreach my $f ( @files ) {
chomp($f);
print "processing $dir/$fn";
`./foobar $dir/$f`;
}
 
Just because...

Also takes the path of the directory, but doesn't behave well if there are subdirectories, because I'm lazy.

[pre]
#!/bin/csh

if ( -d $1 ) then
foreach file ( $1/* )
echo "Processing $file"
foobar $file
end
endif
[/pre]
 

Weekly Prediction Contest

* Predict HORNS-AGGIES *
Sat, Nov 30 • 6:30 PM on ABC

Recent Threads

Back
Top