The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 08-31-2007
piooooter piooooter is offline
Registered User
  
 

Join Date: Mar 2006
Posts: 24
[KSH] Split string into array

Hi,

Is there any way to convert a string into an array in KSH? In other words I want to split the string like this:

Code:
STRING="one two three four"
into an array of 4 values splitting on white space. The array should be similar to the one that would be created with the following command:

Code:
set -A STRING "one two three four"
Is there any way to do it in one instruction, not using a loop like this one:

Code:
   i=0
   for WORD in `echo ${STRING}`; do
        STRING2[$i]=$WORD
        ((i=i+1))
    done