Reputation: 33358
I'm trying to invoke a native Windows command from Cygwin using run
, but as it happens, the command (which I'm taking from the registry) is already quoted and in several parts:
"C:\path\to\file.exe" -- "some argument"
If I use run "C:\path\to\file.exe" -- "some argument"
from the terminal, it works fine, but as soon as I put it in a Bash script it tries to escape the double quotes and adds single quotes around the entire thing, which ruins it:
\"C:\path\to\file.exe\" -- \"some argument\"
If I put an echo
in before trying to run the command, it displays the expected command, but the run
command fails.
echo $command
run $command
I'm fairly new to bash scripting, so I expect I'm missing something fundamental :)
Update: I think I got confused about the single quotes.
Update: Here's the relevant part of the script:
command=`cat /proc/registry/hkey_classes_root/http/shell/open/command/@`
command=${command/"%1"/$target}
run $command
Here's what I've tried in response to SiegeX's suggestion:
command=`cat /proc/registry/hkey_classes_root/http/shell/open/command/@`
command=(${command/"%1"/$target})
run "${command[@]}"
I've also tried cmd /c
as an alternative to run
, with the same results (works from the terminal but not the script).
Upvotes: 1
Views: 1611
Reputation: 360085
This works for me:
command=$(< /proc/registry/hkey_classes_root/http/shell/open/command/@)
command=${command//\"/}
command=$(cygpath "$command")
command=${command/\%1/$target}
eval run $command
Upvotes: 2
Reputation: 140327
Quote $command
like this: run "$command"
If that doesn't work, try this:
#!/bin/bash
cmd=("C:\path\to\file.exe" "--" "some argument")
run "${cmd[@]}"
Upvotes: 0