@__DIR__ doesn't work properly within backtick `...` notation

Consider the following script:

# this is correct:
println(@__DIR__)

# but this is not, it's just the cwd:
run(`echo $(@__DIR__)`)

# but this works:
foo = @__DIR__
run(`echo $foo`)

I get

/home/samuela/dev/research/julia/odecontrol/difftaichi/electric
/home/samuela/dev/research/julia/odecontrol
/home/samuela/dev/research/julia/odecontrol/difftaichi/electric

which defies all logic to me.

Why does @__DIR__ have a different value when used in backtick notation?

This should be fixed by https://github.com/JuliaLang/julia/pull/37007. Your example should work as expected on master.

2 Likes