It would seem to be because you have nested loops instead of having sequential loops. And, break with no operand only breaks out of the nearest enclosing loop. To break out of two nested loops you would need to use break 2.
Furthermore, the code you have (with nested loops) isn't testing A, B, C, one, two, three; it is testing A, B, C, one, A, B, C, two, A, B, C, three which doesn't seem necessary.
But, even if you fix that, I'm not sure why you're creating arrays and using loops. It looks like a simple case statement would be a better approach:
If you insist on doing it with loops and arrays you would need to make the loops sequential instead of nested:
This User Gave Thanks to Don Cragun For This Post:
The reason for the undesired behaviour that you complain about is easily seen in the trace log given in your post: $VAR's initial contents "B" is compared exactly once - with "A". Not equal - so VAR is assigned "DEFAULT" which is compared against from now, a NEVER will be equal to any of the array elements as given.
Don't use the same variable for (initial) input values and for the results unless you know exactly what you are doing.
Don Cragun showed some way simpler methods to solve your problem - try one of those...
Can someone please help me to learn how to deal with loops, arrays and grep?
I have two arrays (lets say I and j) each in a separate file
And have file with lines of data I need to extract, such as
Ruby Smith: some text here
Ruby Smith: some other text here
Ruby Brown: some text here
Ruby... (10 Replies)
if i declare both but don't input any variables what values will the int array and file pointer array have on default, and if i want to reset any of the elements of both arrays to default, should i just set it to 0 or NULL or what? (1 Reply)
Hi All
I have some directories on our server which are containing .csv files. i need to print value of cell "B2" from those csv files. Please advise.
I have tried head command as example: head -2 */Book_Collection_Report_1_-_Collection_Requests_trials.csv | sed -n "3p" | awk -F","... (4 Replies)
Hi, I am starting to enhance my scripting knowledge and need some assistance with simple 1 line for loops. This may help to do a mass permissions change on a big apache doc root while I have an insane customer on my phone.
What is the best resource to learn this skill and what are some that... (5 Replies)
PHP question...
I have an SQL query that's pulled back user IDs as a set of columns. Rather than IDs, I want to use their names.
So I have an array of columns $col with values 1,7,3,12 etc and I've got an array $person with values "Fred", "Bert", "Tom" etc
So what I want to do is display the... (3 Replies)
hi guys,
i have an array called ARRAY which has elements in it... i am trying to assign elements of ARRAY to master_array..
i get a =: command not found error..
i=0
while
do
${master_array}=${ARRAY}
((i++))
done
is there something i am missing? (4 Replies)
Ok, I've already completed the task this is for, but now I'm trying to go back and find more eloquent solutions for future reference. I have a report I've generated that is formatted like this:
1033 1
1079 4
1453 5
2205 6
1933 7
461 8
646 9
1655 12
975 13
1289 14
The first number is... (3 Replies)
Hi
I've a file like so:
Now, I want to read my file and take ex. the Media ID and the Type for each groups of Media (Media1,Media2,...,Media(n):
cat /tmp/file|\
while read FILE
do
while $(FILE|cut -d: -f1)=Media$i
do
#here will be some test, ex:
#if Media ID < 23
... (4 Replies)
Hi,
I am trying to write a script which will loop until a certain action has been performed. I have two files i would like to compares.
For example:
file1 has a list of user ids (about 900) from the company's e-mail server.
file2 has a list of user ids (about 50 or so) from... (7 Replies)
Can anybody help please.
I am trying to right a script which will loop until a certain action has been performed. For example i current have two batch jobs i would like to put into a wait status. Batch Jobs A and B . The script i am trying to get to work is below.
jobs="A B"
COUNT=0
while... (2 Replies)