Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

nesting loop help

Status
Not open for further replies.

uuperl

Programmer
Feb 20, 2006
33
US
Hi,

I need print out like this:

i=one two three four five
p=a b c d e

output should be:
one a
two b
three c
four d
five e

here is what I have but is not doing the trick:
for i in one two three four five
do
for p in a b c d e
do
echo $i $p
done
done

Thanks!
 
How is it not doing the trick?

It's producing "one a one b one c one d one e two a two b ..", is that right?

What you would need is:[tt]
for i in 'one a' 'two b' ...[/tt]
using one loop instead of two.
 
Hi,

You can use standard shell arguments as the inner loop
Code:
# set argument list the second collection
set a b c d e
for i in one two three four five
do
        echo $i $1
        shift #shift argument list to left
done
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top