I'm trying to run a shell command from Julia which needs to have an environment variable set to some specific value. I have two problems:
How to set environment variables to be used by Julia's run(command, args...; wait::Bool = true)
command?
How to pass special sign $
to this process without interpolating it? I want to test if the variable is available for my program.
Let's say I want to define an environment variable FOO=bar
and check if it's accessible within the shell with shell command echo $FOO
.
To prevent Julia interpolating $
I already quoted it like explained in the official documentation but then echo is printing $PATH
and not its value.
So for FOO
I got the following output
julia> run(`echo '$FOO'`)
$FOO
Process(`echo '$FOO'`, ProcessExited(0))
but would have expected something like
julia> run(`echo '$FOO'`)
Process(`echo '$FOO'`, ProcessExited(0))
if FOO
is undefined or
julia> run(`echo '$FOO'`)
bar
Process(`echo '$FOO'`, ProcessExited(0))
if the value is set to bar
.
Check out the Julia documentation on environment variables. You can set an environment variable with:
julia> ENV["FOO"] = "bar"
"bar"
and you can retrieve the value of an environment variable with:
julia> ENV["FOO"]
"bar"
julia> ENV["PATH"]
"really long string of my path"
As you've already stated, you can avoid interpreting the $
by single-quoting that part of your run
command. I'm not totally sure what you are looking for there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With