bash IFS

Updated: 07 March 2024

Explode a string about a comma character, using the Internal Field Separator variable

mystr=foo,bar,spam

IFS=',' read -ra frags <<< $mystr
for frag in "${frags[@]}"; do
  echo "$frag"
done

# output
foo
bar
spam

Leave a comment