CuriousNewbie
CuriousNewbie

Reputation: 329

Bash: more than 1 variable in "For-in" Loop?

example:

for i in 1 2 3 4, j in 7 8 9 0
do
echo $i"="$j
done

output:

1=7
2=8
3=9
4=0

i know this code will throw you a lot of error right away, but is there any way?

Upvotes: 0

Views: 28

Answers (1)

Arount
Arount

Reputation: 10403

There is no such thing in Bash, but you can get your desired output:

foo=(1 2 3 4)
bar=(7 8 9 0)

for (( i=0; i<${#foo[@]}; i++ ))
do
    echo "${foo[$i]}=${bar[$i]}"
done

Upvotes: 2

Related Questions