この質問の拡張: Bash:スペースを含む文字列に余分な一重引用符を追加する
コマンドの引数を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 変数の展開が行われないのはなぜですか?