Bash Script
Florian Diesch
diesch at spamfence.net
Sat Jan 13 07:14:03 UTC 2007
"OOzy Pal" <oozypal at gmail.com> wrote:
> The script below check my project directory and adds a new project.
> For example if the projects I have are:
>
> 000-X
> 001-Y
>
> runnign the script as
>
> script Z
>
> will add a new project 003-Z
>
> but How about if I do
>
> script Z
>
> again? The script will add another project as 004-Z. I would like to
> modify the script so it check if the project already exist them it
> should not create a new one. It should create the same project with
> the same old number
>
> script Z
>
> should not create 004-Z; no, it should recreate 003-Z again.
========================================================================
#!/bin/bash
PROJECT="$1"
WORKINGDIR="/tmp/foo/"
cd "$WORKINGDIR"
if ls -d [0-9][0-9][0-9]-"$PROJECT" > /dev/null 2>&1; then
PROJECT="$(ls -d [0-9][0-9][0-9]-"$PROJECT"|sort -n|tail -1)"
echo "Reusing $PROJECT"
exit 255
fi
if ls [0-9][0-9][0-9]-* > /dev/null; then
num="10#$(ls -d [0-9][0-9][0-9]-* |cut -d- -f1|sort -n|tail -1)"
else
num=0
fi 2>/dev/null
num="$((num + 1))"
num="$(printf %03d $num)"
PROJECT="$num-$PROJECT"
mkdir "$PROJECT"
echo "Created $PROJECT"
========================================================================
Florian
--
<http://www.florian-diesch.de/>
More information about the ubuntu-users
mailing list