Making backup to .doc file .... sh

im tring to make backup to the files end with "doc" extension but the code give me error ... what is the problem!!!!

#! /bin/sh


if [ "$1" = "-k" ]
then

    for name in `ls *.DOC`
    do
        kk= $(printf "%s_temp" $name)
        cp $name $kk
    done

else
echo "error"

You are pasting _temp to the end of filename.doc, which gets you filename.doc_temp.

"for FILE in `ls *.DOC`" is a combo useless use of backticks and useless use of ls *. Literally useless -- for "FILE in *" would do the same thing.

In case you end up with ".doc" instead of ".DOC" I'd suggest using [dD][oO][cC] instead of hardcoded uppercase:

for FILE in *.[dD][oO][cC]
do
        BACKUP="${FILE/.[dD][oO][cC]/.temp.doc}"
        echo mv "$FILE" "$BACKUP"
done

thanx for reply

but it is not working!!!!

Please do not PM me to get a faster response.

In what way is it "not working"? What does it do? Did you remove the echo from in front of mv? I put that there to make sure it showed you what it was going to do instead of trashing your files if that wasn't what you wanted...

you dont need to be arrogant...

You're far from the only one who's been PM-poking me and I've gradually gotten a bit sick of it.

In order to help you I need you to answer my questions. In what way is it "not working"? What does it do? Did you remove the echo from in front of mv? I put that there to make sure it showed you what it was going to do instead of trashing your files if that wasn't what you wanted.

Please post

What Operating System you are running.
The current version of the script.
What you typed.
What you expected the system to reply.
How the system actually replied - verbatim.

@maga6610 When dealing with professionals it pays to be specific. Phrases like "the code give me error" and "but it is not working" are both poor English grammar and not much help towards resolution of your problem.

Ps. I can be just as arrogant as anybody.

dear "methyl"
i dont need anyone to ask me question ... if you dont know the answer ... just leave

Ps. im not proud that im using English

something else ... i found the solution ... so i don't need anybody who consider him a professional

The answer I gave works fine for me. But it doesn't work for you, therefore more information is needed to understand why. We could have helped you in 5 minutes, instead of the days you took, if you'd bothered answering the question. Which one of us is arrogant again? And would you have considered it rude if I'd PM-ed you to get a faster answer from you?

P.S. If you're accusing me of being Methyl, that's hilarious.

LOL

It was hard to tell from the first post whether there were typing errors in the post (like the extra space character) or whether that was the problem. Needed to know about the environment and to see how the script was invoked and what happened.