Reputation: 51
I'm trying to run a simple shell script example:
STR="qwe;ert;rty;tii"
IFS=';' read -r NAMES <<< "$STR"
This is giving me the following 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 identical.
Any feedback would help
Thanks
Upvotes: 0
Views: 375
Reputation: 295443
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:
str='qwe;ert;rty;tii'
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[@]}"
Upvotes: 1