user6656104 user6656104 - 2 months ago 10
Bash Question

Shell syntax IFS

I'm trying to run a simple shell example:

IFS=';' read -r NAMES <<< "$STR"

This is giving me the following error
and this is the full error message:

syntax error: got <&, expecting Word

I'm not exactly sure why this isn't working. I thought the syntax I used was
correct and I tried comparing to other examples and I saw the syntax was almost
Any feedback would help



This is MKS bash, not GNU bash. It's not really bash, and doesn't support the genuine shell's syntax.

There are perfectly good (...well, reasonably adequate) builds of GNU bash for Windows. Use them.

Particularly, in real bash, to split a semicolon-separated string into an array of names:

IFS=';' read -r -a names <<<"$str"

...which you can then verify with

declare -p names

or emit one-to-a-line with

printf '%s\n' "${names[@]}"