I have a program that accepts an argument of the style -g "hello world".
For the program to work correctly, -g and "hello world" actually have to be two separate arguments.
The shell script below is thought to automate something:
MYPROG=/path/to/bin
MYARG=-g\ \"hello\ world\"
"$MYPROG" "$MYARG"
Of course, this doesn't work because -g "hello world"is treated as a single argument by bash.
One solution would be to split -g and "hello world" directly in the shell script to have something like:
MYPROG=/path/to/bin
MYARG1=-g
MYARG2=\"hello\ world\"
"$MYPROG" "$MYARG1" "$MYARG2"
This would work because now the two arguments are treated as such.
However, because -g and "hello world" belong together, the shell script would look kind of awkward. Especially if there are hundreds of arguments defined like this in the script.
Now my question is, how can I get my shell script to treat the one variable as two arguments without splitting them into two variables?