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.
给定以下由jsawk生成的字符串:
[123,456,789]
有没有一种惯用的方式将其转换为 BASH 中的数组?
去掉括号,然后用IFS逗号分隔,然后用read.
IFS
read
foo="[123,456,789]" IFS=, read -a list <<< "${foo:1:-1}"
这可以容纳任何逗号分隔的字符串。
您只需将标点符号转换为空格。
string='[123,456,789]' array=(${string//[^0-9]/ })