Scripting problem - when the file is not found i want it to return to the menu


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Scripting problem - when the file is not found i want it to return to the menu
# 1  
Old 03-04-2009
Scripting problem - when the file is not found i want it to return to the menu

when the file is not found i want it to return to the menu, however it carries out the next line when i hit a key

I know its probably something simple can anyone help?

here is my pause function:

function pause(){
read -s -n 1 -p "Press any key to return to Menu . . ."
echo
}

SCRIPT CODE

echo "Enter file name: "
read fname;

if [ -f $fname ]; then
echo "$fname found"
else
echo "$fname not found"
pause
fi
echo "Enter directory for file to be copied to: "
read dname;
if [ -d $dname ]; then
cp $fname $dname
echo "file copied"
sleep 5
else
echo "$dname not found"
sleep 5

fi;;
# 2  
Old 03-04-2009
Quote:
Originally Posted by Alendrin
when the file is not found i want it to return to the menu, however it carries out the next line when i hit a key

Use a while loop:

Code:
while :
do
   : print menu
   : get input here
   : use some condition to break out of the loop if input OK
done

# 3  
Old 03-04-2009
Try this:

Quote:
function pause(){
read -s -n 1 -p "Press any key to return to Menu . . ."
echo
}

#SCRIPT CODE

gotoMenu="TRUE"

echo "Enter file name: "
read fname;

while [[ ${gotoMenu} -eq "TRUE" ]]
doif [ -f $fname ]; then
echo "$fname found"
echo "Enter directory for file to be copied to: "
read dname;
if [ -d $dname ]; then
cp $fname $dname
echo "file copied"
sleep 5
gotoMenu="FALSE" # To exit after copying
else
echo "$dname not found"
sleep 5
# Set the gotoMenu flag to FALSE if
# need to exit else will continue
# going to MENU
fi
else
echo "$fname not found"
pause
fi
done
regards,
Arun.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to find a file based on pattern & return the filename if found?

Hi all, I am a newbie here. I have this requirement to find a file based on a pattern then return the filename if found. I created a script based on online tutorials. Though, I am stuck & really appreciate if anyone can have a quick look & point me to the right direction? #Script starts... (10 Replies)
Discussion started by: buster_t
10 Replies

2. Homework & Coursework Questions

Shell scripting/menu

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Write a shell menu program that will: a. copy a file to a designated directory b. tell you if a specified user... (13 Replies)
Discussion started by: Jagst3r21
13 Replies

3. Shell Programming and Scripting

Execution Problem with dispalying file content using menu driven script

HI All.. below is my menu options script. in option 2,3 and 4 im giving input and they are saving into their respective text file. problem is when im trying to "cat" those files in options 7,8 and 9 im not getting the output. no respective file contents are displaying on screen. but if i... (1 Reply)
Discussion started by: saichand1985
1 Replies

4. UNIX for Dummies Questions & Answers

Scripting menu problem

Hi there, I am new to Unix and at the moment I am trying to solve my assignment that is to create a script for the program to prompt user to type three codes, from user point of view it should be done by typing codes separating them by spaces. Then program displays a menu with these three... (5 Replies)
Discussion started by: Dannel
5 Replies

5. Shell Programming and Scripting

Validate an IP address - Return to menu

hi! I need a script that, among other things, presents a menu to the user, checks the user input for an IP address (in quad dotted notation), and then "redirects" (with sed) that IP address to the Firewall script. The script must check that all of the inputs are valid IP addresses (numeric,... (1 Reply)
Discussion started by: zetetic
1 Replies

6. Shell Programming and Scripting

help with scripting a simple menu

Hi there. I'm trying to teach myself UNIX but the book I bought is a bit confusing. I'm trying out this exercise and I think I'm on the right track, but I'd appreciate any suggestions on how to improve what I have so far. Also, I'm not clear on how to use the read command to utilize the user's... (3 Replies)
Discussion started by: Jsmith
3 Replies

7. Shell Programming and Scripting

Menu list in Unix csh - command not found

Hello, im taking a class of Unix and i dont really know much about it, im trying to create a list of menu a user would select from and im very lost. Basically it will have 5 options, the user will chose from: 1. list files in the pwd 2. display date and time 3. is the file file or directory 4.... (5 Replies)
Discussion started by: morava
5 Replies

8. Shell Programming and Scripting

Return a message when a file is not found

Hi there, I am writing a script to look for tmp log files that have not been access within the last 10 days. I am using the follwing command within the script: find /var/tmp -name *log -atime -9 ¦xargs What I would like to be able to do would be to display a message if there is no... (3 Replies)
Discussion started by: lodey
3 Replies

9. Shell Programming and Scripting

How to scan a file for literal, return 0 or 1 if found?

How can i scan a file in a UNIX script and look for a particular keyword? For example if i wanted to scan the file "lpcmp165.out" and see if it contains the term "error" or "ERROR" and then return a 0 or 1 or some indicator as such? Detail example: sqlplus -s xx/yyyyyyy#@zzz <<EOF >... (11 Replies)
Discussion started by: bobk544
11 Replies

10. Shell Programming and Scripting

scripting for menu

Hi, I'm writting a script to filter a cvs log and get only the modified files to move them to a specific directory to compile. I try to filter a line and move from source to target, with no results. Could you help me? for example, in the cvs log file appears: cat log.txt U... (2 Replies)
Discussion started by: Manu
2 Replies
Login or Register to Ask a Question