Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

Example:

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?

share|improve this question
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
add comment

1 Answer 1

# 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"
done
a
b c
d
e
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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