while loop problems


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting while loop problems
# 1  
Old 05-12-2008
while loop problems

I have a problem validating my script. The start of my script begins like this:

Quote:
while yesno=[Yy][Ee][Ss]

do
then after this i have all of my script and functions.

at the end i close the loop with this code:

Quote:
echo "Would you like to run the HITS search again?: "
read yesno

done
What i want to know is, how do i make the loop so that only Yes or no can be an answer?

and if the wrong thing is entered how do i get an error message to appear?
# 2  
Old 05-12-2008
How about doing a search using "while loop" and see what you can find ??
# 3  
Old 05-12-2008
Try a select statement, like this

select action in "blabla" "blabla" "quit"
do
case $action in
"blabla")
somecommand
;;
.... for each possible command a $action
"quit")
break
;;
*)
print "this is not an option, try again"
;;
esac
done

have fun
gnom
# 4  
Old 05-13-2008
ok i hate to sound like a complete lamen, but could you spell it out for me a bit better than that for me please. I am a complete beginner and dont really know much about it.

sorry to be a pain.
# 5  
Old 05-13-2008
It's easier to understand when you format your code so that's more manageable to work with and read ...
Code:
select action in "blabla" "blabla" "quit" 
do

  case $action in
    "blabla")  echo "I was passed blabla."
               echo "Now executing a command..."
               somecommandhere ;;  #.... for each possible command in $action
    "quit")    break ;;
    *)         print "this is not an option, try again" ;;
  esac

done

The select statement reads the values after 'in' ... "blabla" "blabla" "quit" .
Then selects each one in turn and passes the value to $action to use within the select statement.
$action is used in the case statement, here the value is compared to those listed values contained within the case statement and if a match is made, executes the code attached to that match. If the value of $action doesn't match any value contained within the case statement, then it is passed to (or rather picked-up by) the statements associated with '*'.

Hope that ruff explaination is of some benefit.

Cheers,
Cameron
# 6  
Old 05-13-2008
thanx cameron for the explanation
# 7  
Old 05-13-2008
no probs gnom - I hope it's accurate - I don't remember the details, only the structure of it. So was kinda fluking it to put it into words. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Korn Shell Loop Problems

Very new to the Korn Shell, but I've been looking up loops online and it seems this should work. I'm just trying to convert an ip range in variables $A and $B and iterate the individual ip's out to new lines. Unfortunately I get {152..155} instead of 152, 153, 154, and 155. # for i in {$A..$B};... (8 Replies)
Discussion started by: Azrael
8 Replies

2. Shell Programming and Scripting

awk loop using array:wish to store array values from loop for use outside loop

Here's my code: awk -F '' 'NR==FNR { if (/time/ && $5>10) A=$2" "$3":"$4":"($5-01) else if (/time/ && $5<01) A=$2" "$3":"$4-01":"(59-$5) else if (/time/ && $5<=10) A=$2" "$3":"$4":0"($5-01) else if (/close/) { B=0 n1=n2; ... (2 Replies)
Discussion started by: klane
2 Replies

3. AIX

for loop problems

I have a script that loops through a list of users to list files owned by these users for u is `cat users.list` do echo $u >> result.out find /home -user $u >> result.out find /var -user $u >> result.out find /opt -user $u >> result.out find /usr -user $u >> result.out done an so... (3 Replies)
Discussion started by: Dardeer
3 Replies

4. Shell Programming and Scripting

loop problems...

#!/bin/bashi function userrecord() { read -p "please enter a number: " a clear output=$(grep -w "$a" appraisalrecord) b=$(echo $a | tr -dc ) if ]; then echo -e "accepted\n" else echo -e "The input must be a numerical number\n" userrecord fi if ]; then echo -e "the ID has... (2 Replies)
Discussion started by: bassmasta1
2 Replies

5. UNIX for Dummies Questions & Answers

I'm having problems with a simple for loop on a newline

for i in `seq 1 10 ` ; do printf $i '\n'; done gives me this: 1234567891064mbarch ~ $ (output followed by bash prompt) :( I've tried so many ways to create a newline at the end. Does anyone have any ideas.. Thanks in advance. Sorry (7 Replies)
Discussion started by: 64mb
7 Replies

6. Shell Programming and Scripting

problems calling out variables in a loop

good afternoon forums. i have a problem that ive been trying to work out all morning and cant seem to get my head around it. what i have in my script is individual letters saved in different variables. so if the word unix was saved then 'u' would be stored in the variable 'wvar1' 'n' in 'wvar2'... (7 Replies)
Discussion started by: strasner
7 Replies

7. Shell Programming and Scripting

Using variables created sequentially in a loop while still inside of the loop [bash]

I'm trying to understand if it's possible to create a set of variables that are numbered based on another variable (using eval) in a loop, and then call on it before the loop ends. As an example I've written a script called question (The fist command is to show what is the contents of the... (2 Replies)
Discussion started by: DeCoTwc
2 Replies

8. Shell Programming and Scripting

Problems with syntax in a loop (AWK)

Hi guys, I'm trying to loop through a number of files that is set by whatever is in a field. eg. The idea is to split FILELIST down into fields, it could contain 1 - 999 fields and it's bar delimited. I thought simple, count the number of fields in the field and then loop... (1 Reply)
Discussion started by: Peejay
1 Replies

9. Shell Programming and Scripting

Problems with an if/then loop within a script

Hi there, I have written a script to clear out log files from the var/tmp dir. It works up to a point. What I needed to do was to exit the script if there was no files to be deleted. I can get this working on a test script but when I implement it into my program it errors out with a `then` not... (3 Replies)
Discussion started by: lodey
3 Replies

10. Shell Programming and Scripting

While loop problems

Here it wont terminate unless i take the not of my statement #!/bin/bash grabXML parseXML TAIL=5 #"$(cat dailyCasLog | tail -n 1)" COUNT=200 LINE=5 #"$(cat dailyCasLog | head -n $COUNT | tail -n 1)" echo $TAIL echo $LINE while ($LINE!=) do #$LINE">>currentLine folderMaker ... (0 Replies)
Discussion started by: rcunn87
0 Replies
Login or Register to Ask a Question