An extension to this question : Bash : Adding extra single quotes to strings with spaces
After storing the arguments of command as a bash array
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[@]}"
Then storing whole command in an array
finder=( find . "${args[@]}" )
In bash I am able to run the command as below:
"${finder[@]}"
./some file.txt
But when I tried using expect, I am getting error
expect -c "spawn \"${finder[@]}\""
missing "
while executing
"spawn ""
couldn't read file ".": illegal operation on a directory
Why is bash variable expansion not happening here?