The right way to do this is to construct the inner command object normally
and then use Base.shell_quote to interpolate that whole command into a
larger command and then again to interpolate it into yet another level of
command. Like this:

julia> dir = "/some/place"
"/some/place"

julia> host = "localhost:123"
"localhost:123"

julia> exeflags = `-1 -2 -3`
`-1 -2 -3`

julia> sshflags = ``
``

julia> cmd = `cd $dir && julia $exeflags`
`cd /some/place && julia -1 -2 -3`

julia> cmd = `sh -l -c $(Base.shell_escape(cmd))`
`sh -l -c 'cd /some/place && julia -1 -2 -3'`

julia> cmd = `ssh -n $sshflags $host $(Base.shell_escape(cmd))`
`ssh -n localhost:123 "sh -l -c 'cd /some/place && julia -1 -2 -3'"`


This way you don't need to mess around with multiple levels of escaping by
hand and it should work for all kinds of crazy option values you might pass
into the innermost command. I really need to export and document
shell_split and shell_escape. They should probably be renamed to cmd_split
and cmd_escape since they specifically split and escape Julia's command
syntax, not arbitrary shell syntax, although it is pretty close to what
most shells do.


On Mon, Mar 3, 2014 at 2:18 AM, Amit Murthy <[email protected]> wrote:

> It has to.
>
> It is actually this line -
> https://github.com/JuliaLang/julia/blob/master/base/multi.jl#L1139
>
>
> On Mon, Mar 3, 2014 at 12:45 PM, Ismael VC <[email protected]>wrote:
>
>> Don't surround the expresion in quotes to get what you want:
>>
>> ulia> exeflags = `1 2 3`
>> `1 2 3`
>>
>> julia> `"julia $exeflags"`
>> `'julia 1' 'julia 2' 'julia 3'`
>>
>> julia> `julia $exeflags`
>> `julia 1 2 3`
>>
>>
>>
>>
>>
>

Reply via email to