Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试运行一个简单的 shell 脚本示例:
STR="qwe;ert;rty;tii" IFS=';' read -r NAMES <<< "$STR"
这给了我以下错误消息:
syntax error: got <&, expecting Word
我不确定为什么这不起作用。我认为我使用的语法是正确的,我尝试与其他示例进行比较,发现语法几乎相同。
任何反馈都会有所帮助
谢谢
这是 MKS bash,而不是 GNU bash。它不是真正的 bash,也不支持真正的 shell 语法。
有非常好的(...嗯,相当充足的)用于 Windows 的 GNU bash 构建。使用它们。
特别是,在真正的 bash 中,将分号分隔的字符串拆分为名称数组:
str='qwe;ert;rty;tii' IFS=';' read -r -a names <<<"$str"
...然后您可以使用它进行验证
declare -p names
或发出一对一
printf '%s\n' "${names[@]}"