Results 1 to 2 of 2
Perhaps it would be easiest to show you what I'm trying to do with the code and output...
Code:
#!/bin/sh
national=( "us_radar" "-120,26" "-60,52" "1500" "650" )
iowalocal=( "iowa" "-99.25,37.5" ...
- 03-05-2008 #1Just Joined!
- Join Date
- Mar 2008
- Location
- Ames, IA
- Posts
- 1
bash - Passing arrays into for-loop variable?
Perhaps it would be easiest to show you what I'm trying to do with the code and output...
Output:Code:#!/bin/sh national=( "us_radar" "-120,26" "-60,52" "1500" "650" ) iowalocal=( "iowa" "-99.25,37.5" "-87.25,45.5" "900" "600" ) echo ${#national[*]} echo ${#iowalocal[*]} for site in ${national} ${iowalocal}; do echo ${#site[*]} done
I've verified that national[0] or iowalocal[0] is the one item that actually gets passed into site. Is there some way to pass entire arrays into a for-loop variable? I can restructure my code with five arrays instead and just do for num = 0 1 etc., but that's a bit messy for this script's purpose.Code:5 5 1 1
Thanks for any help you can provide!Last edited by j.patton; 03-05-2008 at 10:28 PM. Reason: fixed title
- 03-07-2008 #2Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
To print the elements of an array you can do something like:
Have a read of this:Code:for i in $(seq 0 $((${#national[*]} - 1))) do echo "${national[$i]}" done
http://tldp.org/LDP/abs/html/arrays.html
Regards


Reply With Quote