http://qs321.pair.com?node_id=710203


in reply to Five Ways to Reverse a String of Words (C#, Perl 5, Perl 6, Ruby, Haskell)

No bash solution yet, so here it goes (pure bash, no external binaries):

STR=" one two three four " ARR=($STR) LEN=${#ARR[*]} LAST=$(($LEN-1)) ARR2=() I=$LAST while [[ $I -ge 0 ]]; do ARR2[ ${#ARR2[*]} ]=${ARR[$I]} ## push I=$(($I-1)) done echo ${ARR2[*]}

--
David Serrano