escaping double quotes inside backticks?

165 views
Skip to first unread message

John Brock

unread,
Oct 8, 2015, 7:16:34 PM10/8/15
to julia-users
I'm trying to construct a command containing double quotes, e.g.: scp "StrictHostKeyChecking no" source us...@127.0.0.1:~

However, I can't figure out how to escape the double quotes when using the julia backtick syntax. For example, none of the following work:

julia> `scp "StrictHostKeyChecking no" source us...@127.0.0.1:~`
`scp 'StrictHostKeyChecking no' source us...@127.0.0.1:~`


julia
> `scp \"StrictHostKeyChecking no\" source us...@127.0.0.1:~`
`scp '"StrictHostKeyChecking' 'no"' source us...@127.0.0.1:~`


julia
> `scp """StrictHostKeyChecking no""" source us...@127.0.0.1:~`
`scp 'StrictHostKeyChecking no' source us...@127.0.0.1:~`


Any suggestions?

Steven G. Johnson

unread,
Oct 8, 2015, 7:35:07 PM10/8/15
to julia-users


On Thursday, October 8, 2015 at 7:16:34 PM UTC-4, John Brock wrote:
I'm trying to construct a command containing double quotes, e.g.: scp "StrictHostKeyChecking no" source us...@127.0.0.1:~

However, I can't figure out how to escape the double quotes when using the julia backtick syntax. For example, none of the following work:

julia> `scp "StrictHostKeyChecking no" source us...@127.0.0.1:~`
`scp 'StrictHostKeyChecking no' source us...@127.0.0.1:~`

First, are you sure you actually want to pass double quotes to `scp`?  Double quotes are used in the shell to prevent spaces from being parsed as separate arguments, they aren't actually passed to `scp`.   The above example is correct if you want to pass 
     StrictHostKeyChecking no
as the first argument of scp, and is equivalent to 
     scp "StrictHostKeyChecking no" source us...@127.0.0.1:~
in a shell like bash.

If you actually wanted to pass double quotes to `scp` as part of the arguments, you would escape them exactly a you would declare a literal string with quotes in Julia:
     julia> `scp "\"StrictHostKeyChecking no\"" source us...@127.0.0.1:~`

     `scp '"StrictHostKeyChecking no"' source us...@127.0.0.1:~`


--SGJ
      

John Brock

unread,
Oct 9, 2015, 12:28:19 AM10/9/15
to julia-users
A-ha, I see, thanks. Also, for anyone who comes across this post, I forgot the -o flag before 'StrictHostKeyChecking no'.
Reply all
Reply to author
Forward
0 new messages