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

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

xcode - Swift Playground - Files are not readable -

jboss7.x - JBoss AS 7.3 vs 7.4 and differences -