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
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.
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.
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:
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.)
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
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?