0
array=('' '' 2 4); for f in ${array[@]}; do echo a; done
a
a

I expected four "a" rows here as there are 4 elements of array

$ echo ${#array[@]}

4
4
  • 1
    "${array[@]}". many many duplicate questions will be found. Commented Mar 6, 2017 at 15:13
  • what do you mean? Commented Mar 6, 2017 at 15:14
  • 2
    Also, please follow this advice from the tag info before asking questions with bash: "For shell scripts with errors, please check them in shellcheck.net before posting here." Commented Mar 6, 2017 at 15:34
  • Thank you rici, shellcheck gave right answer. I didnt notice that advice Commented Mar 7, 2017 at 7:00

1 Answer 1

1

You must quote the variable for correct using:

array=('' '' 2 4); for f in "${array[@]}"; do echo a; done

and btw. search for simular answers :)

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. Was unable to find. Honestly.

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.