# Julia command line evaluation with string in the expression

**URL:** <https://discourse.julialang.org/t/julia-command-line-evaluation-with-string-in-the-expression/104333>\
**Category:** General Usage\
**Tags:** question\
**Created:** [September 28, 2023, 4:45am UTC](https://discourse.julialang.org/t/julia-command-line-evaluation-with-string-in-the-expression/104333 "2023-09-28T04:45:05Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shuhua](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shuhua/32/27618_2.png) [@Shuhua](https://discourse.julialang.org/u/Shuhua)\
**Post date:** [September 28, 2023, 4:45am UTC](https://discourse.julialang.org/t/julia-command-line-evaluation-with-string-in-the-expression/104333/1 "2023-09-28T04:45:05Z")

</div>

I am using PowerShell on Windows. Did not figure out how I can include a string in the expression when evaluating it in the command line.  
Examples:

```bash
PS F:\WJ\SmartPark\CMS\code\COPT_HTTP> julia -e 'x = 123'
PS F:\WJ\SmartPark\CMS\code\COPT_HTTP> julia -e "x = 'ok'"
ERROR: syntax: character literal contains multiple characters
Stacktrace:
 [1] top-level scope
   @ none:1
PS F:\WJ\SmartPark\CMS\code\COPT_HTTP> julia -e 'x = "ok"'
ERROR: UndefVarError: ok not defined
Stacktrace:
 [1] top-level scope
   @ none:1
PS F:\WJ\SmartPark\CMS\code\COPT_HTTP> julia -e "x = "ok""
ERROR: syntax: incomplete: premature end of input
Stacktrace:
 [1] top-level scope
   @ none:1
PS F:\WJ\SmartPark\CMS\code\COPT_HTTP> julia -e "x = \"ok\""
ERROR: syntax: incomplete: invalid string syntax
Stacktrace:
 [1] top-level scope
   @ none:1
PS F:\WJ\SmartPark\CMS\code\COPT_HTTP> julia -e " x = \"ok\" "
ERROR: syntax: incomplete: invalid string syntax
Stacktrace:
 [1] top-level scope

```

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [September 28, 2023, 5:46am UTC](https://discourse.julialang.org/t/julia-command-line-evaluation-with-string-in-the-expression/104333/2 "2023-09-28T05:46:40Z")

</div>

Works for me in a Unix shell, where both `julia -e 'x = "ok"'` and `julia -e "x = \"ok\""` work fine. So it must be some weirdness with PowerShell quoting rules or Windows command-line parsing. You could try WSL as a workaround.

---

<div class="post-metadata">

**Author:** ![Shuhua](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shuhua/32/27618_2.png) [@Shuhua](https://discourse.julialang.org/u/Shuhua)\
**Post date:** [September 28, 2023, 6:16am UTC](https://discourse.julialang.org/t/julia-command-line-evaluation-with-string-in-the-expression/104333/3 "2023-09-28T06:16:28Z")

</div>

Yes, it seems so. I found that `julia -e "x = \"ok\""` works in Windows CMD terminal, but still failed in PowerShell.

---

<div class="post-metadata">

**Author:** ![g-gundam](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/g-gundam/32/47593_2.png) [@g-gundam](https://discourse.julialang.org/u/g-gundam)\
**Post date:** [September 28, 2023, 6:44am UTC](https://discourse.julialang.org/t/julia-command-line-evaluation-with-string-in-the-expression/104333/4 "2023-09-28T06:44:22Z")

</div>

Maybe someone who knows PowerShell’s [quoting rules](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_quoting_rules?view=powershell-7.3) better can chime in, but I managed to get this to work on PowerShell for Linux.

```plaintext
PS /home/anon> julia -e 'x = \"ok\"; println(x)'
ok

```

In most other shells, those backslashes wouldn’t be necessary, but something weird is going on.

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [September 28, 2023, 10:36am UTC](https://discourse.julialang.org/t/julia-command-line-evaluation-with-string-in-the-expression/104333/5 "2023-09-28T10:36:57Z")

</div>

In Powershell, you do not need to escape double quotes within single quotes. To escape double quotes, use two of them.

---

<div class="post-metadata">

**Author:** ![johnh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnh/32/3615_2.png) [@johnh](https://discourse.julialang.org/u/johnh)\
**Post date:** [September 28, 2023, 2:53pm UTC](https://discourse.julialang.org/t/julia-command-line-evaluation-with-string-in-the-expression/104333/6 "2023-09-28T14:53:49Z")

</div>

How about installing MobaXterm and getting a bash shell?  
This may not be what you want, but could help.

---

<div class="post-metadata">

**Author:** ![Shuhua](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shuhua/32/27618_2.png) [@Shuhua](https://discourse.julialang.org/u/Shuhua)\
**Post date:** [September 28, 2023, 3:24pm UTC](https://discourse.julialang.org/t/julia-command-line-evaluation-with-string-in-the-expression/104333/7 "2023-09-28T15:24:39Z")

</div>

Could you please give an example?

---

<div class="post-metadata">

**Author:** ![g-gundam](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/g-gundam/32/47593_2.png) [@g-gundam](https://discourse.julialang.org/u/g-gundam)\
**Post date:** [September 28, 2023, 4:08pm UTC](https://discourse.julialang.org/t/julia-command-line-evaluation-with-string-in-the-expression/104333/8 "2023-09-28T16:08:46Z")

</div>

@Shuhua  
Double double quotes.

```plaintext
PS /home/anon> julia -e 'x = ""ok""; println(x)'
ok

```

Surprisingly, this doesn’t work:

```plaintext
PS /home/anon> julia -e "x = ""ok""; println(x)"
ERROR: UndefVarError: `ok` not defined
Stacktrace:
 [1] top-level scope
   @ none:1

```

However, this works.

```plaintext
PS /home/anon> julia -e "x = \""ok\""; println(x)"
ok

```

---

<div class="post-metadata">

**Author:** ![Jeff\_Emanuel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff_emanuel/32/15440_2.png) [@Jeff\_Emanuel](https://discourse.julialang.org/u/Jeff_Emanuel)\
**Post date:** [September 28, 2023, 6:55pm UTC](https://discourse.julialang.org/t/julia-command-line-evaluation-with-string-in-the-expression/104333/9 "2023-09-28T18:55:54Z")

</div>

> [@stevengj](#):
>
> s for me in a Unix shell, where both `julia -e 'x = "ok"'` and `julia -e "x = \"ok\""` work fine. S

Whenever I get to quoting-hell in the Windows command line, I break out the `sh` that came with git. For me, that is most common when I need to use `curl`.
