I try to create an array that is filled up with some values. But i don't know how to do it. I tried something below but it didn't work.
My code:
i=0
for c in colors; do
array[$i]=$c
echo {$c[$i]}
i=`expr $i + 1`
done
note: "colors" is some kind of "ps -ef" command that returns a list of values. it has "blue,red,yellow" values for example.
colors= 'ps -ef | grep colors'
colorslist is returned is important. If they're returned one-to-a-line, there are more reliable ways to get them out than string-splitting (which is what you're doing, and which is what your accepted answer does, which will change, for instance, a color*to a list of files in the current directory, or a colorlight magentato two entries,lightandmagenta).(( ++i ))is the modern way to writei=$(expr $i + 1).{$c[$i]}rather than${c[$i]}andin colorsrather thanin $colors.pgrepcommand rather than grepping the output ofps.