Oh, no wonder I couldn't get this to work:
julia> withenv("FOO"=>"bar") do run(`bash -c "echo FOO is \$FOO"`) end
ERROR: syntax: "run(Base.cmd_gen((("bash",),("-c",),("echo FOO is
","$FOO"))))" is not a valid function argument name
Of course the do..end needs to be over multiple lines.
I can't believe I didn't think of this. (Perhaps the documentation could be
slightly improved at that point...)
As for the shell expansion thing, thanks for explaining that. This would
never have occurred to me. I appreciate your help.
Bill.
On Saturday, 10 October 2015 02:41:18 UTC+2, Steven G. Johnson wrote:
>
>
>
> On Friday, October 9, 2015 at 8:34:19 PM UTC-4, Bill Hart wrote:
>>
>> indicates that withenv can also be used with a do..end block. However,
>> try as I might, I cannot figure out how to do anything with this. Can
>> someone provide an example of this in operation.
>>
>
> julia> *withenv("FOO"=>"bar") do*
>
> * run(`bash -c "echo FOO is \$FOO"`)*
>
> * end*
>
> FOO is bar
>
>
>
>>
>> Whilst I'm asking trivial questions, I may as well also ask this related
>> one.
>>
>> If I do:
>>
>> run(`echo \$PATH`)
>>
>
> The $FOO syntax is a feature of the shell, not of /bin/echo. When you
> run(`echo ...args...`) you are executing /bin/echo directly, without
> involving the shell, so no shell expansions like * patterns or $variables
> are performed.
>
> If you want to use the $FOO syntax, you need to invoke the shell, as in my
> example above where I invoked bash.
>
>>