How to execute echo $PATH from Julia

I would like to run echo $PATH bash command, see the result and optionally capture it in a string or array of strings. I started with:

julia> run(`echo $PATH`)
ERROR: UndefVarError: PATH not defined
julia> run(`echo \$PATH`)
$PATH

which doesn’t work.

Probably this is what you are looking for?

julia> ENV["PATH"]

julia> my_variable = ENV["PATH"]
3 Likes

You need to invoke a shell that interprets the $ for you:

run(`bash -c "echo \$PATH"`)
5 Likes