How can I read in POSIX bash
input like this:
<name>,<tag1> <tag2> <tag3>…
I tried
while read line;do done
but this wants newlines, all I have is spaces.
(Is IFS solution? If yes, how? (I don't fully understand IFS.))
Use an array:
echo '<name>,<tag1> <tag2> <tag3>' | while IFS=" ," read -a foo; do echo ${foo[@]}; done
Output:
<name> <tag1> <tag2> <tag3>
From man bash
:
IFS: The Internal Field Separator that is used for word splitting after expansion and to split lines into words with the read builtin command.
tr
anslate spaces to newlines. (tr ' ' '\n'
)echo '<name>,<tag1> <tag2> <tag3>' | tr ", " "\n"
?