bash: split string to array

bash: split string to array

 There are few possible ways of splitting a string with delimiter-separated values to an array in Bash. Here I present five of them.

1. Using tr command

This method will produce incorrect array due to space in „567 5“, but it works fine if there are no spaces in the $STR variable.

2. Using IFS (Internal Field Separator) variable

This method works fine even if there are spaces.

3. Using read command

This method also works fine even though there are spaces in the $STR variable.

4. Using sed command

This method will also produce incorrect array due to space in „567 5“, but it works fine if there are no spaces in the $STR variable.

5. Using set command

This method also works fine.

Source: http://shortrecipes.blogspot.co.at/2010/02/bash-split-string-to-array.html