Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Renaming a File using user input filename

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi!
Does anybody know how to do the following:
example existing file: test.txt (with contents)
How to rename this file to test2.txt presuming the information "test.txt" is keyed in by the user.

Ex.
Screen Output: What file name do you want to rename to test2.txt?
User Input:test.txt
Result: script renames test.txt to test2.txt
TY!
-RicaM


 
Doesn't mv test.txt test2.txt suit your purposes?

Alternatively in a script do something like:

echo "Please enter name of file to be renamed test2.txt:"\n
read filename
mv $filename test2.txt
exit

should do the trick. HTH.
 
Sorry, the:

echo "Please enter name of file to be renamed test2.txt:"\n

should have been:

echo "Please enter name of file to be renamed test2.txt: \c"

to accept user input on the same line as the prompt.

Cheers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top