Remove spaces in filenames

Hi,

I have files like below, In files coming as spaces. Before transfering those files into ftp server. I want to remove the spaces and then can transfer the files into unix server.

e.g: filenames are

1) SHmail _profile001_20120908.txt

2) SHmail_profile001 _20120908.txt

3) sh mail_profile001_20120908.txt

thx in advance

for i in `ls`
do
file=echo $i | tr -d " "
mv $i $file
done
for i in *.txt; do newName=${i// /}; mv "$i" $newName; done

---------- Post updated at 02:56 PM ---------- Previous update was at 02:53 PM ----------

you need to quote the $i and check the above correction

and instead of using

 
for i in `ls'
 
use
 
for i in *

Or better yet, use:

for i in *\ *

and

mv "$i" "$newName"

bash/ksh93:

for i in *\ *; do
  mv "$i" "${i// }"
done

Careful that the target file does not already exist...