Bash Read a string field by field


Example

Let's assume that the field separator is :

var='line: 1
line: 2
line3'
while IFS= read -d : -r field || [ -n "$field" ]; do
   echo "-$field-"
done <<< "$var"

Output:

-line-
- 1
line-
- 2
line3
-