I am trying to create a variable with multiple values, and use it in a command that will execute these values one by one.


value=(a, b, c, d, e)

By using echo "$value" I would like these values to be passed on to echo one by one.

When I use ARRAY=(a, b, c, d, e), they all get executed at once. Which I'm trying to avoid.

Any ideas?

  • 3
    Then loop through the array with a for. By the way, no comma between the values. (Or those values actually contain the commas too?) – manatwork Dec 20 '13 at 19:31
# declare the array
ARRAY=( a "b c" d e )

# to get the elements out of the array, use this syntax:
#   "${ARRAY[@]}" -- with the quotes

for element in "${ARRAY[@]}"; do
    echo "$element"
b c
  • Works great, thx. – Danijel Jan 16 at 13:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.