1

I'm trying to make a shell script but I'm stuck.

This doesn't work and I don't know why.

a=( "1" "2" )
b=( "3" "4" )
c=( "$a" "$b" )

for d in "${c[@]}"; do
    echo "${d[1]}"
done
betseg
  • 157
  • 8
  • 13

1 Answers1

2

With bash:

a=( "1" "2" )
b=( "3" "4" )

# concatenate array a and b to new array c
c=( "${a[@]}" "${b[@]}" )

for d in "${c[@]}"; do 
  echo "$d"
done

Output:

1
2
3
4
Cyrus
  • 77,979
  • 13
  • 71
  • 125