# How can I interpolate inside single quotes inside a command?

**URL:** <https://discourse.julialang.org/t/how-can-i-interpolate-inside-single-quotes-inside-a-command/56515>\
**Category:** General Usage\
**Created:** [March 5, 2021, 12:41am UTC](https://discourse.julialang.org/t/how-can-i-interpolate-inside-single-quotes-inside-a-command/56515 "2021-03-05T00:41:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![BridgeBot](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bridgebot/32/21491_2.png) [@BridgeBot](https://discourse.julialang.org/u/BridgeBot)\
**Post date:** [March 5, 2021, 12:41am UTC](https://discourse.julialang.org/t/how-can-i-interpolate-inside-single-quotes-inside-a-command/56515/1 "2021-03-05T00:41:19Z")

</div>

How can I interpolate inside single quotes inside a command?

```julia
h = "hey"
`echo $h` # this works
`echo '$h'` # this does not

```

Note that the original poster on Slack cannot see your response here on Discourse. Consider _transcribing the appropriate answer back to Slack_, or pinging the poster here on Discourse so they can _follow this thread_.  
[(Original message :slack:)](https://julialang.slack.com/archives/C6A044SQH/p1614904473386700?thread_ts=1614904473.386700&cid=C6A044SQH) [(More Info)](https://github.com/JuliaCommunity/SlackBridge)

---

<div class="post-metadata">

**Author:** ![miguelraz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/miguelraz/32/631_2.png) [@miguelraz](https://discourse.julialang.org/u/miguelraz)\
**Post date:** [March 5, 2021, 12:43am UTC](https://discourse.julialang.org/t/how-can-i-interpolate-inside-single-quotes-inside-a-command/56515/2 "2021-03-05T00:43:44Z")

</div>

Answering my own question  
I wanted this command

````julia
julia> run(```WolframKernel -run 'Print["$h"];Exit[];'```)
Mathematica 12.2.0 Kernel for Linux x86 (64-bit)
Copyright 1988-2020 Wolfram Research, Inc.
$h
Process(`WolframKernel -run 'Print["$h"];Exit[];'`, ProcessExited(0))

````

to output this

````julia
julia> run(```WolframKernel -run 'Print["$h"];Exit[];'```)
Mathematica 12.2.0 Kernel for Linux x86 (64-bit)
Copyright 1988-2020 Wolfram Research, Inc.
hey
Process(`WolframKernel -run 'Print["$h"];Exit[];'`, ProcessExited(0))

````

This can be done by prefacing the double quotes with `\`"

````julia
julia> run(```WolframKernel -run "Print[\"$h\"];Exit[];"```)
Mathematica 12.2.0 Kernel for Linux x86 (64-bit)
Copyright 1988-2020 Wolfram Research, Inc.
hey
Process(`WolframKernel -run 'Print["hey"];Exit[];'`, ProcessExited(0))

````

Hat tip to @simeonschaub.

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [March 5, 2021, 7:25pm UTC](https://discourse.julialang.org/t/how-can-i-interpolate-inside-single-quotes-inside-a-command/56515/3 "2021-03-05T19:25:40Z")

</div>

I would really advise against ever trying to tie yourself in knots with literal quotes inside `Cmd`s. The whole point of them is to _avoid_ ever using quotes in the first place. If you want to pass a _string_ to an external command, well, first create the string:

```plaintext
julia> h = "hey"
"hey"

julia> str = """Print["$h"];Exit[];"""
"Print[\"hey\"];Exit[];"

julia> `WolframKernel -run $str`
`WolframKernel -run 'Print["hey"];Exit[];'`

```

The Cmd object will actually pretty-print the object with underlines to underscore each independent argument that’s getting passed — and it even prints as though it were quoted for you:

![image](https://global.discourse-cdn.com/julialang/original/3X/4/0/409c36fdd240b34de4889b896d4539122d926fef.png)

---

<div class="post-metadata">

**Author:** ![miguelraz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/miguelraz/32/631_2.png) [@miguelraz](https://discourse.julialang.org/u/miguelraz)\
**Post date:** [March 11, 2021, 9:00pm UTC](https://discourse.julialang.org/t/how-can-i-interpolate-inside-single-quotes-inside-a-command/56515/4 "2021-03-11T21:00:49Z")

</div>

Thanks a lot @mbauman, that does seem quite a bit more sensible. I found a work around for my needs, but this is still useful.
