【发布时间】:2016-11-03 14:41:45
【问题描述】:
我想构建一个包含带引号的单词组的字符串。 这些组应该转到相同的函数参数。 我试着玩数组。 字面上构造的数组有效,但我仍然希望找到 裸字符串的神奇语法破解。
# literal array
LA=(a "b c")
function printArgs() { # function should print 2 lines
while [ $# -ne 0 ] ; do print $1 ; shift; done
}
printArgs "${LA[@]}" # works fine
# but how to use string to split only unquoted spaces?
LA="a \"b c\""
printArgs "${LA[@]}" # doesn't work :(
LA=($LA)
printArgs "${LA[@]}" # also doesn't work :(
bash 数组有一个问题,它们不能通过传送带传输 -(回声/$())。
【问题讨论】:
-
当然不是。如果它是可能的,那么就不需要数组了。