Pass digits of a numeric string to an array in bash -
i have number, say
number=5684398
and want store digits fields of array coolarray
follows:
coolarray[0]=5 coolarray[1]=6 coolarray[2]=8 coolarray[3]=4 coolarray[4]=3 coolarray[5]=9 coolarray[6]=8
how can proceed?
you can use fold -w1
break input string each character:
number=5684398 coolarray=( $(fold -w1 <<< "$number") ) printf "%s\n" "${coolarray[@]}" 5 6 8 4 3 9 8
Comments
Post a Comment