Hi, I was wondering if there is a “rule” to write commands with nested quotes that work. Here is an example with 3 nested commands (bash calling bash calling julia). My final goal is slightly different (a julia call passed to a program which is itself called through ssh), but I hope if I can get this example to work I will understand better how to solve the problem.
So here is what I tried.
e = quote println("It works") end
jcall = "julia -e '$(string(e))'"
cmd = `bash -c $jcall`
# run(cmd) # OK!
cmd2 = `bash -c $cmd`
# run(cmd2) # Does not work
So here I don’t understand, I thought building a command with backticks would ensure proper escaping (or even avoid needing to escape, if the arguments are passed directly to the command without running a shell, not sure I really understood everything here).
Then I tried:
cmd_str = "bash -c \"$jcall\""
cmd2 = `bash -c $cmd_str`
# run(cmd2) # does not work
jcall = "julia -e \\\'$(string(e))\\\'"
cmd_str = "bash -c \'$jcall\'"
cmd2 = `bash -c $cmd_str`
# run(cmd2) # does not work
cmd_custom = `bash -c "bash -c \"julia -e 'begin println(\\\"It works\\\") end'\""`
println(cmd_custom)
# run(cmd_custom) # ok
jcall = "julia -e '$(string(e))'"
cmd_str = "bash -c \"$(escape_string(jcall))\""
cmd2 = `bash -c $(cmd_str)`
println(cmd2)
# run(cmd2) # does not work ("\" is not a unary operator)
I especially don’t understand the last example, which I thought would work (Is there a different escape level between the quotes and the \n ? Or what is wrong ?)