arrays - Bash - need help splitting a string by colon -


i having trouble using ifs (as internet has led me issue) - keep getting error saying "ifs: command not found" trying split string ':' , store in array, looks a:b:c:d:x:y:z stored in array holds, a, b, c, d, x, y, z elements. have written is

ifs = ':' read - r -a arr <<< "$info"  

where info string being read in file containing multiple strings in aforementioned format reading them in way:

while read info 

lastly when try assign first element in array variable, getting error:

export name = $info[0]  

the 2 errors here export: '=' not valid identifier , export: '[0]: not valid identifier

i relatively newcomer bash, suggests great. thank in advance.

the basic problem here code contains spaces in places aren't allowed. instance, following fine syntax (though fails comply posix conventions on variable naming, advises lowercase characters used application-defined names):

info_string='a:b:c:d:x:y:z' ifs=: read -r -a info_array <<< "$info_string"  

similarly, on dereference, need curly braces, , (again) can't put spaces around =:

name=${info_array[0]} 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -