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

Re: Copy a file one hundred times



On Sat, Dec 13, 2008 at 07:35:44PM +0100, Manon Metten wrote:
> Hi Rodolfo
> 
> On Sat, Dec 13, 2008 at 8:12 PM, Rodolfo Medina
> <rodolfo.medina@gmail.com> wrote:
> 
> > I need the right syntax to copy file.jpg 100 times with one command so to get
> > 100 files named file1.jpg, file2.jpg, ..., file100.jpg.
> 
> 
> #!/bin/bash
> 
> for x in `seq 1 100`; do
> 
>     if [[ x -lt  10 ]]; then cp file.jpg file-00$x.jpg;
> 
>   elif [[ x -lt 100 ]]; then cp file.jpg file-0$x.jpg;
> 
>   else cp file.jpg file-$x.jpg;
> 
>   fi
> 
> done

I forgot about seq. This is even better (the -w left pads with zero for
equal width):

for x in $(seq -w 1 100); do cp file.jpg file${c}.jpg; done

-- 
"Faith is often the boast of the man who is too lazy to investigate."
		-- F.M. Knowles
    Rick Pasotto    rick@niof.net    http://www.niof.net


Reply to: