Issue
I have a way to siplt the string into a array with shell ,but the array seems no value
>>> a='11 12 13 14'
>>> echo $a | awk '{split($0,arr," ")'
1 11
2 12
3 13
4 14
>>> echo ${arr[0]}
>>>
the expected result should be
>>> echo ${arr[0]}
11
how could I store the value into the array after the string splitted
Solution
If the values are "nice" - no filename expansion trigger characters and elements are nicely separated by spaces - just read the array.
arr=($a)
A way better and safer version, is to use readarray or mapfile.
readarray -d ' ' -t arr < <(printf "%s" "$a")
readarray -t arr <<<"${a// /$'\n'}"
Answered By - KamilCuk Answer Checked By - Marilyn (WPSolving Volunteer)