Need help with Interactive rename file.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help with Interactive rename file.
# 1  
Old 12-11-2008
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
# 2  
Old 12-11-2008
Quote:
Originally Posted by keyboardkowboy
hey all i was writing a script to

Were you? Or is this a homework assignment?
Quote:

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.

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

Use printf instead.
Quote:
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.

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

Did it not cover while loops?
Quote:
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
# 3  
Old 12-11-2008
i thought "\c:" will was to allow the user or me to input the response in the same line.
# 4  
Old 12-11-2008
Quote:
Originally Posted by keyboardkowboy
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
# 5  
Old 12-11-2008
Quote:
Originally Posted by vidyadhar85
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.
# 6  
Old 12-11-2008
Quote:
Originally Posted by keyboardkowboy
i thought "\c:" will was to allow the user or me to input the response in the same line.

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.
# 7  
Old 12-11-2008
Quote:
Originally Posted by cfajohnson

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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash to copy file 3 times and rename based on another file

In the below bash I am trying to copy the only text file (always only one) in /home/cmccabe/Desktop/list/QC/metrics.txt and rename each of the 3 text files according to /home/cmccabe/Desktop/test/list.txt using lines 3, 4 ,5. This format (that is list.txt) is always 5 lines. Thank you :). ... (12 Replies)
Discussion started by: cmccabe
12 Replies

2. Shell Programming and Scripting

Rename specific file extension in directory with match to another file in bash

I have a specific set (all ending with .bam) of downloaded files in a directory /home/cmccabe/Desktop/NGS/API/2-15-2016. What I am trying to do is use a match to $2 in name to rename the downloaded files. To make things a more involved the date of the folder is unique and in the header of name... (1 Reply)
Discussion started by: cmccabe
1 Replies

3. UNIX for Dummies Questions & Answers

awk - Rename output file, after processing, same as input file

I have one input file ABC.txt and one output DEF.txt. After the ABC is processed and created output, I want to rename ABC.txt to ABC.orig and DEF to ABC.txt. Currently when I am doing this, it does not process the input file as it cannot read and write to the same file. How can I achieve this? ... (12 Replies)
Discussion started by: High-T
12 Replies

4. Shell Programming and Scripting

Interactive filters for log file (beginner)

Hello, I have a software which log all entry from internet and save it in text file. For example (fake): 10:02:23:124.id_0000.1:"blalba" 10:05:26:124.id_0000.1:"blalba" 10:10:32:124.id_0000.1:"blalba" 11:32:36:124.id_0000.1:"blalba" 11:33:49:124.id_0000.1:"blalba"... (6 Replies)
Discussion started by: acidoangel
6 Replies

5. Shell Programming and Scripting

A script that will move a file to a directory with the same name and then rename that file

Hello all. I am new to this forum (and somewhat new to UNIX / LINUX - I started using ubuntu 1 year ago).:b: I have the following problem that I have not been able to figure out how to take care of and I was wondering if anyone could help me out.:confused: I have all of my music stored in... (7 Replies)
Discussion started by: marcozd
7 Replies

6. Homework & Coursework Questions

How to write script that behaves both in interactive and non interactive mode

Q. Write a script that behaves both in interactive and non interactive mode. When no arguments are supplied it picks up each C program from the directory and prints first 10 lines. It then prompts for deletion of the file. If user supplies arguments with the script , then it works on those files... (8 Replies)
Discussion started by: rits
8 Replies

7. Homework & Coursework Questions

Help with Interactive / Non Interactive Shell script

Q. Write a script that behaves both in interactive and non interactive mode. When no arguments are supplied it picks up each C program from the directory and prints first 10 lines. It then prompts for deletion of the file. If user supplies arguments with the script , then it works on those files... (1 Reply)
Discussion started by: rits
1 Replies

8. UNIX for Dummies Questions & Answers

Rename file based on first 3 characters of data in file

I'm looking to determine if I can use a grep command to read file and rename the file based on the first 3 characters of the data in the file. An example is: Read FileA If the first 3 positions of the data in the file are "ITP", then rename the file as FileA_ITP, else if the first 3... (3 Replies)
Discussion started by: jchappel
3 Replies

9. UNIX for Dummies Questions & Answers

.bashrc file is an initialization file run by each interactive invocation

I search the web and found the following statements ..... The /etc/profile file is a system wide initialization script which is run at login time for each user, while .profile is the users own login initialization. The .bashrc file is an initialization file run by each interactive invocation... (1 Reply)
Discussion started by: cy163
1 Replies

10. UNIX for Dummies Questions & Answers

Help with multiple file rename - change case of part of file name

Hi there, I hope someone can help me with this problem : I have a directory (/var/www/file/imgprofil) which contains about 10000 JPG files. They have a naming convention thus : prefix-date-key-suffix.jpg they all have the prefix p-20050608- then AAAA is a 4 letter code the suffix is... (7 Replies)
Discussion started by: steve7
7 Replies
Login or Register to Ask a Question