![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| nested loop problem | mmunir | Shell Programming and Scripting | 5 | 07-04-2008 03:16 AM |
| the given code goes in infinite loop and does not increment variable i | mrityunjay22 | Shell Programming and Scripting | 6 | 12-26-2007 02:20 AM |
| Increment date in 'for' loop? | SunnyK | Shell Programming and Scripting | 4 | 10-30-2007 06:12 AM |
| Variable in While Loop Nested If | geass | Shell Programming and Scripting | 6 | 03-26-2007 06:09 PM |
| nested loop | chinog | Shell Programming and Scripting | 5 | 04-20-2005 10:45 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Hi ,
I am trying to increment the nested for loops parellely,but i cant ,i used continue 2 but the second loop not getting increment. no1="1 6 5 4 8" no2="4 7 8 0 1" for var1 in $no1 ; do for var2 in $no2 ; do line1 line 2 line 3 continue 2 done done Please help on this |
|
|||||
|
Hi.
It is not clear what your goal is. In your construction, every time you enter the inner loop, the sequence will begin again -- that's the nature of the loop. Here's how I would do this, but it is guessing what you are trying to accomplish: Code:
#!/bin/bash -
# @(#) s2 Demonstrate array use for processing in parallel.
# See http://www.tldp.org/LDP/abs/html/arrays.html for details on
# arrays.
echo
echo "(Versions displayed with local utility \"version\")"
version >/dev/null 2>&1 && version "=o" $(_eat $0 $1)
set -o nounset
echo
echo " Results:"
no1=( 1 6 5 4 8 )
no2=( 4 7 8 0 1 )
length=${#no1[*]}
echo " length is $length"
i=0
while (( i < length ))
do
echo iteration $i no1[$i] = ${no1[$i]}, no2[$i] = ${no2[$i]}
(( i++ ))
done
exit 0
Code:
% ./s2 (Versions displayed with local utility "version") Linux 2.6.11-x1 GNU bash 2.05b.0 Results: length is 5 iteration 0 no1[0] = 1, no2[0] = 4 iteration 1 no1[1] = 6, no2[1] = 7 iteration 2 no1[2] = 5, no2[2] = 8 iteration 3 no1[3] = 4, no2[3] = 0 iteration 4 no1[4] = 8, no2[4] = 1 |
|
||||
|
A construct which works even in Bourne Classic (tm) is to run the variables in parallel in a while loop, like this:
Code:
while read var1 var2; do : stuff done <<HERE 1 4 6 7 5 8 4 0 8 1 HERE |
|
||||
|
Thanks for this...
|
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Tags |
| increment nested for loop |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|