@__DIR__ different inside command (`...`)

This MWE demonstrates it:

code = raw"""
@show cmd = `echo $(@__DIR__)`
@show thisdir = @__DIR__
@show cmd2 = `echo $(thisdir)`
"""
file = tempname() * ".jl"
write(file, code)
cd(expanduser("~"))
include(file)

as it prints

cmd = #= /tmp/julia4jHJh2.jl:1 =# @cmd("echo \$(@__DIR__)") = `echo /home/tamas/`
thisdir = #= /tmp/julia4jHJh2.jl:2 =# @__DIR__() = "/tmp"
cmd2 = #= /tmp/julia4jHJh2.jl:3 =# @cmd("echo \$(thisdir)") = `echo /tmp`
`echo /tmp`

Is this a bug? v"1.1.0-DEV.439".

@yakir12

1 Like