0

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?

1 Answer 1

2

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 
Sign up to request clarification or add additional context in comments.

3 Comments

i see... I was just hoping that it exist somehow because of the convenience, unlike the answer that you provided, where we have to create those variables outside, before the loop. so i have a question about ${#foo[@]} what does the # mean, why it should be in front of foo, and whats @, why it sould be inside []? ive been encountering codes like that and it makes me dizzy.
${} is dynamic variable call syntax. # before foo ask for the length of the array foo, [@] returns all items within foo, so we get the actual size of the full array
okay, so #= length of and @=items and also it only works in ${} i suppose ...noted it, thanks

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.