Changing extension

Hi ,
I need to replace the file name extension with txt to csv,i wrote the below script when executing its giving the below error.Please anyone how to do this?

$ a2.sh
mv: *.: cannot access: No such file or directory
./a2.sh[7]: o: bad number
$ vi a2.sh

a2.sh
-----
#!/bin/ksh
txt=$1
csv=$2
for file in *.$txt ; do
mv $file ${file%$txt}$csv
done
exit o

Thanks ,
Mohan

ur script looks wrong...
for loop expects a list for action.
"for file in *.$txt" means what???
if u are providing list as the 1st argument ( as u wrote in ur code) than why u are not supplying list when executing the script.

if u want to do with all the file in the current dir use
for file in `/bin/ls *.txt`

and if as an argument, use for file in $*

correct me anyone if i m wrong...

If you want to rename all the '.txt' files to '.csv' :

for file in $(ls *.txt 2>/dev/null)
do
   mv $file ${file%.txt}.csv
done

The error './a2.sh[7]: o: bad number' comes from your exit statement.
Replace the 'o' by '0'.

HI,

Thanks,this is waht i am looking for

Thanks,
Mohan

With zsh:

autoload -U zmv
zmv -W '*.txt' '*.csv'

Or if you have rename:

rename .txt .csv *.txt