Splitting a string by colon

Viewed 1508

I am trying to split the string by ':' and store it in an array, so something that looks like a:b:c:d:x:y:z will be stored in an array which holds, a, b, c, d, x, y, z as elements.

What I have written is

IFS = ':' read - r -a ARR <<< "$INFO" 

where INFO is a string which is being read in from a file containing multiple strings in the aforementioned format.

I get an error saying "IFS: command not found".

I am reading them in this way:

while read INFO

Lastly when I try to assign the first element in the array to a variable, I am getting an error:

export NAME = $INFO[0] 

the two errors I get here are export: '=' not a valid identifier and export: '[0]: not a valid identifier

I am relatively a newcomer to bash.

2 Answers
Related