From anishsane's answer and comments in it, we now know what you want. Here's the same bashier style using a for loop. See the Looping Constructs section of the reference guide . I also use printf instead of echo .
#!/bin/bash array=( "Vietnam" "Germany" "Argentina" ) array2=( "Asia" "Europe" "America" ) for ((i=0;i<${#array[@]};++i)); do printf "%s is in %s\n" "${array[i]}" "${array2[i]}" done
Another possibility is to use an associative array:
#!/bin/bash declare -A continent continent[Vietnam]=Asia continent[Germany]=Europe continent[Argentina]=America for c in "${!continent[@]}"; do printf "%s is in %s\n" "$c" "${continent[$c]}" done
Depending on what you want to do, you may also consider this second option. But note that it will not be easy for you to control the order when the fields are displayed in the second possibility (well, this is an associative array, so this is not surprising).
gniourf_gniourf Jul 01 '13 at 17:10 2013-07-01 17:10
source share