Need help with Interactive rename file.

hey all i was writing a script to

  1.  Rename a file upon the user's request.  If the file exists, prompt the user for confirmation before renaming the file. The screen should prompt the user for
    

a. �Name of file you want to rename.� Use the �\c� escape character.
b. �New name of file� Use the �\c� escape character.
c. �File Exist� to avoid overriding a file.
d. �File $oldname changed to $newname�
e. �Do you want to rename another file?� If the user selects �yes� the system should refresh the screen and if the user selects �no� the system should exit to the prompt sign.
f. Refresh the screen to go back to the menu until the user selects the exit option.

so far this is what i got so far, but im stuck and i dont know how to approach the rest of it.

heres the code.

echo ""
echo "* Chuck Ingrid "
echo "
Renaming Files Interactively *"
echo "
"
echo "* 1. Select R or r to rename your file "
echo "
2. Select E or e to exit the screen "
echo "
*****************************************"
#
echo
echo "0: exit"
echo "R or r: To rename your file
echo "E or e: Exit the screen"
echo "Enter your choice: \c"
read option
case $option in
1) echo "Enter File name to rename: \c"
read response

Were you? Or is this a homework assignment?

Why use \c? It is not supported in many shells or systems.

Use printf instead.

If you can't do better than this, you'd better take the course over.

Did it not cover while loops?

i thought "\c:" will was to allow the user or me to input the response in the same line.

yes you are right and it is supported by AIX. in other system you have to add -e option with echo

i run the program in HP version of UNix in the SH shell and the "\c" works fine and i know i have to add echo. but the problem is that im just stuck at option "b" part of the script and im good at diagramming the steps i need to write the script but when it comes to write it i dont know the proper loops to use.

It's purpose, on those systems that support it, is to suppress the newline that echo normally prints after displaying its arguments.

You cannot rely on its working, which is why it is better to use printf.

ohk i will use printf but can you review my code and tell me if it even comes close to the list of operations i want it to follow. cuz im just writing codes using a book. i am not a seasoned vet like you guys on here. i just starting operating unix last month.

Have you looked at your shell's man page? Or at other posts in this or other forums? Or any of the many shell tutorials on the Web?

This implements an infinite loop. It will continue looping until you execute a break statement:

while true
do
   : do whatever
done

so it what part of my script do i put that in.

can you give me one reason why can't we relay on its working??

Because it is not supported on many systems.

On Linux with bash or ash or dash or pdksh or ksh93, or on FreeBSD with sh or ksh or bash, or on NetBSD with bash or sh or ksh, or on SunOS with sh or ksh, etc., you get this:

$ echo "qwerty\cuiop"
qwerty\cuiop
$ 

so i guess there no hope for my script to work in the order i want it to:confused:

Run the script and see what it does. If it does what you want, it works. If it doesn't, fix it. If you have trouble fixing it, come back here and ask for help about the specific part that is not working.

Post only the part of the code that is not working. Post any error messages you get. (Cut and paste them; do not retype them.)

ok thanks

Of course there is. It's a fairly simple script.

Tackle it one part at a time.

if look in that way every OS is different on its on way so does that mean we can't relay on codes working??
i mean to say if we have a option available in our OS there is nothing wrong in using it

If, as you claim, you are good at diagramming the program flow, it will be obvious where it needs to go.

The recommended way is to use printf. That is supported consistently; echo is not the same everywhere, so don't use it.

Writing a script that will run on any system is easy if you follow some simple rules. When posting to a public forum, always use the most portable code you can. Then everyone can use it. These posts are not read only by the original poster; other people will benefit from portable code, no matter what system they are on.

Besides, the OP may need to run the script on another system at some time. Why hamstring him by using non-portable code?

the only part of the script that will run is the script header and the options available

the rest of the lines all have syntax errors.

Please follow the instructions in my earlier post: