0

Is it possible to set the IFS to " ,"? Thats a space and comma.

If I have it just as the comma I get this

genres="platform, action adventure, puzzle"
IFS=$','
for g in $genres
do
echo "$g"
done
platform
 action adventure
 puzzle

If I try setting it with the space it splits at single spaces also.

genres="platform, action adventure, puzzle"
IFS=$' ,'    
for g in $genres
do
echo "$g"
done
platform
action
adventure
puzzle

I'm sure I could clean the leading whitespace before or after the loop, but why can't I do it with the delimiter?

Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
Chris
  • 985
  • 2
  • 7
  • 17

0 Answers0