Assign multiword string to a bash array element -
my goal take first word string , assign bash array, firstword{i] , take rest of string , put array, rest[i] i integer counter.
i tried approach: (note: strictly speaking tmp debug)
correction: left indexes off string vars. should string[1] , string[2].
string[1]="one 2 3 four" string[2]="five 6 7 eight" # etc etc ((i=0; < ${#string[@]}; i++ )) set -- ${string[i]} firstword[i]=$1 tmp="${*:2}" rest[i]=$tmp echo $tmp echo ${rest[i]} done rest[i] turns out equal "two" buttmp equals "one tswo three"
so tried:
ifs=$'\n'; rest[i]="${*:2}"; ifs=$' '; no joy.
so, how accomplish task?
found answer. changed:
rest[i]=$tmp to
rest[i]="$tmp" and data read rest kept together.
i assume has bash , command line splitting , globbing data.
Comments
Post a Comment