problem in shell script

I am bit new to shell scripting. Is there any body who can help me

There are n number of files present in folder named like (/girish/1) ),(/girish/2) .....so on, till (/girish/24) folder. I have to delete all the file from all these folders. I have to pass '/girish' path from the file name 'para' which is present in / directory.

I wrote

exec</para
read x
i=1
while test i -le 24
do
cd $x/$i
rm * --------------> till here ever thing is working fine
i=`expr $i + 1`
done

but when I incrment the value of i it must remove the files from /girish/2 , /girish/3 .. so on but it is not happening.Kindly tell me where I am wrong

Instead of i=`expr $i + 1`. I'm new to UNIX, but it might work.

Gabi

or you could do it the hard way .....

for i in 1 2 3 4 5 6 7 8 9 10 11 .... 24; do
cd $x/$i
if [ -f ./* ]
then
rm ./*
fi
done

=w=

This should work for you.

exec</para
read x
i=1
while test $i -le 24
do
cd $x/$i
rm * --------------> till here ever thing is working fine
i=`expr $i + 1`
done

Just a quick word of advice -- it is not a good idea to use

cd blah
rm *

in a script. If you run this script from a directory with important files, and you accidently make a typo when the script is reading for '$x', then the cd command will fail with an error, and the script will continue. You may then be deleting some pretty important stuff!

It would be safer to use rm $x/$i/*
This way if there is any sort of typing error, you will simply receive a 'No such file or directory' error or similar :slight_smile:

Hope this helps.

thanks a ton to every body