Using read in bash without empty fields collapsing
- by Charles Duffy
I'm trying to read a multi-line tab-separated file in bash. The format is such that empty fields are expected. Unfortunately, the shell is collapsing together field separators which are next to each other, as so:
# IFS=$'\t'
# read one two three <<<$'one\t\tthree'
# printf '<%s> ' "$one" "$two" "$three"; printf '\n'
<one> <three> <>
...as opposed to the desired output of <one> <> <three>.
Can this be resolved without resorting to a separate language (such as awk)?