0
$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.

2 Answers 2

2

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

Comments

1

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!

1 Comment

Liked the tip - found it useful in my script!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.