bug-bash
[Top][All Lists]
Advanced

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

Re: would you give me a hand with a simple 'if' bash script?


From: Jan Schampera
Subject: Re: would you give me a hand with a simple 'if' bash script?
Date: Fri, 14 Mar 2008 06:14:01 +0100
User-agent: IceDove 1.5.0.14pre (X11/20080208)

hawa wrote:
> Execuse me, would you give me a hand with a simple 'if' bash script?
> I want to make folders "00", "01",...,"20" and
> copy existing files file_00, file_01,....,file_20 to each folder.
> Thank you very much.
> 
> 
> 
> -------------------------------------
> for ((  i = 1 ;  i <= 20;  i++  ))
> do
> 
> if [ $i -gt 10 ]; then          foldername = $i
>         filename = "file_"
>         filename = $filename$i
> else
>         foldername = "0"$i   ##
>         filename ="file_0"   ##
>         file = $filename$i   ##
> fi
> 
> done

untested:

for ((  i = 1 ;  i <= 20;  i++  ))
do
  foldername=$(printf %02d $i)
  filename=$(printf file_%02d $i)

  # now, do whatever you want with $filename
  # and $foldername (cp, mv, rm, ...)
done

J.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]