# How to interpolate into the \`julia -c\` shell command

**URL:** <https://discourse.julialang.org/t/how-to-interpolate-into-the-julia-c-shell-command/90883>\
**Category:** General Usage\
**Created:** [November 27, 2022, 3:31am UTC](https://discourse.julialang.org/t/how-to-interpolate-into-the-julia-c-shell-command/90883 "2022-11-27T03:31:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lilith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lilith/32/27492_2.png) [@Lilith](https://discourse.julialang.org/u/Lilith)\
**Post date:** [November 27, 2022, 3:31am UTC](https://discourse.julialang.org/t/how-to-interpolate-into-the-julia-c-shell-command/90883/1 "2022-11-27T03:31:15Z")

</div>

I have a bit of julia code in a shell variable. I want to execute it.

When I run this script

```julia
code='import Pkg'
echo $code
julia -e $code
echo pass

```

I get this

```julia
import Pkg
ERROR: syntax: incomplete: premature end of input
Stacktrace:
 [1] top-level scope
   @ none:1

```

When I try to quote the code

```julia
code=\''import Pkg'\'
echo $code
julia -e $code
echo pass

```

I get this

```julia
'import Pkg'
ERROR: syntax: incomplete: invalid character literal
Stacktrace:
 [1] top-level scope
   @ none:1

```

How can I run the code in an environment variable using `julia -c [???]`

---

<div class="post-metadata">

**Author:** ![jd-foster](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jd-foster/32/35824_2.png) [@jd-foster](https://discourse.julialang.org/u/jd-foster)\
**Post date:** [November 27, 2022, 6:31am UTC](https://discourse.julialang.org/t/how-to-interpolate-into-the-julia-c-shell-command/90883/2 "2022-11-27T06:31:24Z")

</div>

> [@Lilith](#):
>
> ```julia
> code='import Pkg'
> echo $code
> julia -e $code
> 
> ```

This issue is that the shell is splitting `'import Pkg'` by space delimiter, so the equivalent of `julia -e 'import` is being executed, hence the `incomplete: premature end of input` error.  
You can control the splitting using the `IFS` shell variable (aka Internal Field Separator or [Input Field Separator](https://en.wikipedia.org/wiki/Input_Field_Separators)). This can be redefined as, say, just a new line character. So wrapping the julia invocation might be the answer here:

```julia
(IFS=$'\n'; julia -e $code)

```

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [November 27, 2022, 11:36am UTC](https://discourse.julialang.org/t/how-to-interpolate-into-the-julia-c-shell-command/90883/3 "2022-11-27T11:36:53Z")

</div>

The standard solution is to quote variables (which you should _ **always** _ do anyway), not to hack `IFS`:

```julia
julia -e "${code}"

```

---

<div class="post-metadata">

**Author:** ![jd-foster](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jd-foster/32/35824_2.png) [@jd-foster](https://discourse.julialang.org/u/jd-foster)\
**Post date:** [November 27, 2022, 11:43am UTC](https://discourse.julialang.org/t/how-to-interpolate-into-the-julia-c-shell-command/90883/4 "2022-11-27T11:43:12Z")

</div>

That’s a better way of doing it!
