I have the following line filename:231:blahblah
that I want to split into an array using :
as the delimiter
The is the code that I have
echo "Text read from file: $line"
IFS=':' read -a FILENAME <<< $line
echo "filename: ${FILENAME[0]}"
actual output is
Text read from file: filename:231:blahblah
filename: filename 231 blahblah
The output I want is
Text read from file: filename:231:blahblah
filename: filename
What am I doing wrong?
Solution 1:
Solution 2 (derived from your try):
Run result: