Bash Script
Felipe Alfaro Solana
felipe.alfaro at gmail.com
Mon Oct 23 23:58:27 UTC 2006
On 10/23/06, OOzy Pal <oozypal at gmail.com> wrote:
> What is wrong with my script. The script reads a directory listing
> which contains projects as:
>
> 01-Proj1
> 02-Proj2
> 03-Proj3
>
> The scripts then extracts the first two digits of the file name,
> compares it to the first two digits of the next file until it finds
> the max number which is in the case 03. The script then increment the
> number (03+1). Next it creates a new project as
>
> 04-Proj4.
>
> --SCRIPT--
> #!/bin/bash
>
> WORKINGDIR="/home/hab/Business/Projects"
>
> PROJECT=$1
> MaxIndex=0
> PRJ=`ls $WORKINGDIR`
> for dir in $PRJ ;
> do
> Num=${dir%%-*}
> if [$MaxIndex -lt $Num]; then
> MaxIndex=$Num
> fi
> done
>
>
> #Num=$((Num+1));
> #Num=$(printf %02d $Num)
>
> #PROJECT=$Num-$PROJECT
What about this one?
#!/bin/bash
PROJECT=$1
MaxIndex=0
for dir in [0-9][0-9]-*;
do
Num=${dir%%-*}
if [ $MaxIndex -lt $Num ]; then
MaxIndex=$Num
fi
done
Num=$((Num+1));
Num=$(printf %02d $Num)
PROJECT=$Num-$PROJECT
echo $PROJECT
More information about the ubuntu-users
mailing list