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

Re: Shell scripting



Hi Pete,

> 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).
> Could someone point out the silly mistake I am obviously making?

[...]

> #!/bin/sh
> #
> # batch zip
> # invoke with batchzip <filespec>
> #
> # this will zip all files in the current directory that conform
> # to the file spec.
> #
> ZIP="/usr/bin/zip"
> ARGS="-mT"
> 
> if [ -n "$1" ]
> then
>     if [ -x "$ZIP" ]
>     then
>         nofiles=0
> 
>         for file in "$1"

That's the problem: you ignore all arguments but the first. Try changing
this line to

          for file

>  do
>             filename=${file%.*}
>             echo "Adding $file to $filename.zip..."
>             $ZIP $ARGS "$filename" "$file" > /dev/null
> 
>             let "nofiles += 1"
>         done
> 
>         echo
>         echo "finished ... processed $nofiles files."
>         echo
>         retval=0
>     else
>         echo
>         echo "Could not find 'zip'. Please check the path."
>         echo
>         retval=2
>     fi
> else
>     echo
>     echo "Usage : `basename $0` <filespec>"
>     echo
>     retval=1
> fi
> 
> exit $retval


HTH, Jukka

-- 
bashian roulette:
$ ((RANDOM%6)) || rm -rf ~



Reply to: