Shuhua
September 28, 2023, 4:45am
1
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:
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
1 Like
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.
1 Like
Shuhua
September 28, 2023, 6:16am
3
Yes, it seems so. I found that julia -e "x = \"ok\""
works in Windows CMD terminal, but still failed in PowerShell.
1 Like
Maybe someone who knows PowerShell’s quoting rules better can chime in, but I managed to get this to work on PowerShell for Linux.
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.
2 Likes
mkitti
September 28, 2023, 10:36am
5
In Powershell, you do not need to escape double quotes within single quotes. To escape double quotes, use two of them.
johnh
September 28, 2023, 2:53pm
6
How about installing MobaXterm and getting a bash shell?
This may not be what you want, but could help.
Shuhua
September 28, 2023, 3:24pm
7
Could you please give an example?
@Shuhua
Double double quotes.
PS /home/anon> julia -e 'x = ""ok""; println(x)'
ok
Surprisingly, this doesn’t work:
PS /home/anon> julia -e "x = ""ok""; println(x)"
ERROR: UndefVarError: `ok` not defined
Stacktrace:
[1] top-level scope
@ none:1
However, this works.
PS /home/anon> julia -e "x = \""ok\""; println(x)"
ok
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
.
1 Like