【发布时间】:2016-03-08 13:50:51
【问题描述】:
这个问题的扩展: Bash : Adding extra single quotes to strings with spaces
将 command 的参数存储为 bash 数组后
touch "some file.txt"
file="some file.txt"
# Create an array with two elements; the second element contains whitespace
args=( -name "$file" )
# Expand the array to two separate words; the second word contains whitespace.
find . "${args[@]}"
然后将整个命令存储在一个数组中
finder=( find . "${args[@]}" )
在 bash 中,我可以运行如下命令:
"${finder[@]}"
./some file.txt
但是当我尝试使用 expect 时,我得到了错误
expect -c "spawn \"${finder[@]}\""
missing "
while executing
"spawn ""
couldn't read file ".": illegal operation on a directory
为什么这里没有发生 bash 变量扩展?
【问题讨论】:
标签: bash expect variable-expansion