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) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -