Problems on cat and substring replacement, shell

Hi

I'm new in the Shell world, and I've been trying the whole day to get my script to work.

I'm under Ubuntu 10.04.

Let me explain:
I want to list all the files matching some regex in a directory, and then make some some string replacement on the name of the files, and then a cat on the files.

Here's my code :

#!/usr/bin/sh
rep='/home/blablabla/'
for filename in `ls ${rep} | grep -i [0-9]-0.txt$`
do 
    if  [ ! -d ${rep}${filename} ]
    then
        filename1=`echo "${filename}" | sed -e "s/-0/-1/g"`
		filename2=`echo "${filename}" | sed -e "s/-0//g"`
		echo "${filename1} ${filename2}"
		cat ${rep}${filename} "${rep}${filename1}" > "${rep}${filename2}"
    fi
done

I would like to know if it's the best way to do that, because it seems to work but i'm not sure if that's really reliable.

Thanks in advance

Regards

Hi,

variable substitution via ${var//exp1/exp2} is a feature of bash
or zsh, not the sh. Consequently your code will not work with
!#/usr/bin/sh. Change it to bash.

HTH Chris

Thanks!