I have a complex script that takes variables from files and uses them to run programs (Wine specifically)
Passing options from the variables in the other file isn’t working as expected:
#!/bin/bash
. settingsfile
wine $run
And in the other file:
run="run.exe -withoption \"This text\""
When I change wine $run to echo wine $run, it echos a string, which when run explicitly works fine:
#!/bin/bash
. settingsfile
wine run.exe -withoption "This text"
Edit: Running with #!/bin/bash -x shows me:
+ wine run.exe -withoption '"This' 'text"'
How do I fix this?
The problem is that
"Thisandtext"are treated as separate arguments, each containing a double-quote, rather than as a single argumentThis text. You can see this if you write a function to print out one argument per line; this:prints this:
rather than this:
The simplest solution is to tack on an
evalto re-process the quoting:But a more robust solution is to have
runbe an array, and then you can refer to it as"${run[@]}":so that the quoting is handled properly from the get-go.