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'
You can use this script to fill up the array in a loop:
array=()
for c in $colors; do
array+=( "$c" )
done
OR even simpler:
array=( $(command) )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With