[Bash] Split a delimited string into an array

Created on November 30, 2026

Use IFS and read -a to split a string into an array. Here, IFS=',' makes the comma the separator and -a array stores the resulting fields in array.

#!/usr/bin/env bash

input="apple,banana,cherry"
IFS=',' read -r -a array <<< "$input"

for element in "${array[@]}"
do
  echo "$element"
done
apple
banana
cherry

The assignment to IFS applies only to this invocation of read.

Bash Shell command