[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Shell scripting



> I have a script that performs batch zipping of files. Trouble is that it
> only does one file at a time (kind of going against the "batch" idea).

And a Perl way (with verbose messages and articulated exit statuses, as you 
seem to be after):

#!/usr/bin/perl
@ARGV 
		or do {print STDERR "Usage: zipit filespec\n"; exit 1};
foreach my $file (@ARGV) {
        -f $file 
		or do {print STDERR "Can't stat file '$file'\n"; exit 2};
        `zip $file.zip $file` 
		or do {print STDERR "Error running zip\n"; exit 3};
}
exit 0;

which could in a pinch be expressed as a one-liner:

perl -e '`zip $_.zip $_` foreach (<*.dat>)'

if you are zipping, e.g. *.dat.




Reply to: