mv command is giving error in shell script

Hi,

In my shell script when I am using mv command using shell variables it is giving me error of syntax. Following is the shell script:

file_edifice="*.txt"
fquote="'"
fdquote=\"

for file in $file_edifice
do
file_name=$fquote$file$fquote
tofile_name=`date "+%d%m%y:%H%M%S:edifice.data"`
echo $filename
echo $tofile_name
mv $file_name $tofile_name
sleep 2
done

errors :

'ACADEMY SPORTS_ACADEMY SPORTS_20071208.txt'
131207:011618:edifice.data
Usage: mv [-f] [-i] [-e warn|force|ignore] f1 f2
mv [-f] [-i] [-e warn|force|ignore] f1 ... fn d1
mv [-f] [-i] [-e warn|force|ignore] d1 d2

'BOSCOVS_BOSCOVS_20071208.txt'
131207:011620:edifice.data

mv: 'BOSCOVS_BOSCOVS_20071208.txt': cannot access: No such file or directory

'DICKS SPORTING GOODS_DICKS SPORTING GOODS_20071208.txt'
131207:011622:edifice.data
Usage: mv [-f] [-i] [-e warn|force|ignore] f1 f2
mv [-f] [-i] [-e warn|force|ignore] f1 ... fn d1
mv [-f] [-i] [-e warn|force|ignore] d1 d2

'SPORT CHALET_SPORT CHALET_20071208.txt'
131207:011624:edifice.data
Usage: mv [-f] [-i] [-e warn|force|ignore] f1 f2
mv [-f] [-i] [-e warn|force|ignore] f1 ... fn d1
mv [-f] [-i] [-e warn|force|ignore] d1 d2

'THE SPORTS AUTHORITY, INC._THE SPORTS AUTHORITY, INC._20071208.txt'
131207:011626:edifice.data
Usage: mv [-f] [-i] [-e warn|force|ignore] f1 f2
mv [-f] [-i] [-e warn|force|ignore] f1 ... fn d1
mv [-f] [-i] [-e warn|force|ignore] d1 d2

Please suggest.

Thanks,
gammit

You are trying to make life much harder than it needs to be.

Especially your $fdquote thing.

The shell interprets many characters and I can't tell if you are trying to assist or confuse the hell out of the interpretor.

thanks for your views porter, so what should I do in this case?

You dont need fquote and fdquote, just use quotes where you need them. It will honestly make it much clearer. The syntax to shell scripts hasn't changed much in 25 years, these things don't need to be variables.

also you don't need the sleep.

Once you've simplified it, then repost it and we can have another look. :slight_smile:

thanks porter, it has been resolved.

Excellent,

:slight_smile: