Zcentric

@Mike Zupan · Aug 13, 2010 · 1 min read

Bash: Turn a string into an array

I needed to turn a string into an array to loop through it. It is pretty simple

SOLR_CORES="core1,core2,core3"
declare -a CORES
CORES=(`echo $SOLR_CORES | tr ',' ' '`)       

for CORE in ${CORES[@]}
do
    stuff here
done