user6656104 user6656104 - 1 year ago 124
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


Answer Source

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[@]}"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download