I want to split a string on a delimiter in zsh on MacOS 11.6.1. I looked at the following questions How do I split a string on a delimiter in Bash?
I tried to reproduce its 2 most upvoted answers as follows:
IN="bla@some.com;john@home.com"
IFS=';' read -ra ADDR <<< "$IN"
for i in "${ADDR[@]}"; do
# process "$i"
done
IN="bla@some.com;john@home.com"
while IFS=';' read -ra ADDR; do
for i in "${ADDR[@]}"; do
# process "$i"
done
done <<< "$IN"
but get the following output : bad option: -a
IN="bla@some.com;john@home.com"
arrIN=(${IN//;/ })
echo ${arrIN[1]} # Output: john@home.com
but get the following output : bla@some.com john@home.com
instead of john@home.com
What am I doing wrong?