Bug Killer
Bug Killer

Reputation: 661

Bash array contents get printed in columns

$declare -a inputs=("(1 3 4 8 6 2 7 0 5)" "(2 8 1 0 4 3 7 6 5)"

$ for i in ${inputs[@]}; do echo $i; done;

gives

(1
3
4
8
6
2
7
0
5)
(2
8
1
0
4
3
7
6
5)

I want each array in a row.

Upvotes: 0

Views: 414

Answers (2)

anubhava
anubhava

Reputation: 785631

Use quotes:

for i in "${inputs[@]}"; do echo "$i"; done;
(1 3 4 8 6 2 7 0 5)
(2 8 1 0 4 3 7 6 5)

Upvotes: 2

devnull
devnull

Reputation: 123608

You need to use quotes. Say:

for i in "${inputs[@]}"; do echo $i; done

This would return:

(1 3 4 8 6 2 7 0 5)
(2 8 1 0 4 3 7 6 5)

Moreover, remove the ; after done unless it's the last line in your script!

Upvotes: 1

Related Questions