@@ -284,22 +284,14 @@ function load_path_expand(env::AbstractString)::Union{String, Nothing}
284284 env == " @temp" && return mktempdir ()
285285 env == " @stdlib" && return Sys. STDLIB
286286 if startswith (env, " @script" )
287- if @isdefined (PROGRAM_FILE )
288- dir = dirname (PROGRAM_FILE )
289- else
290- cmds = unsafe_load_commands (JLOptions (). commands)
291- if any (cmd:: Pair{Char, String} -> cmd_suppresses_program (first (cmd)), cmds)
292- # Usage error. The user did not pass a script.
293- return nothing
294- end
295- dir = dirname (ARGS [1 ])
296- end
297- if env == " @script" # complete match, not startswith, so search upwards
298- return current_project (dir)
299- else
300- # starts with, so assume relative path is after
301- return abspath (replace (env, " @script" => dir))
302- end
287+ program_file = JLOptions (). program_file
288+ program_file = program_file != C_NULL ? unsafe_string (program_file) : nothing
289+ isnothing (program_file) && return nothing # User did not pass a script
290+
291+ # Expand trailing relative path
292+ dir = dirname (program_file)
293+ dir = env != " @script" ? (dir * env[length (" @script" )+ 1 : end ]) : dir
294+ return current_project (dir)
303295 end
304296 env = replace (env, ' #' => VERSION . major, count= 1 )
305297 env = replace (env, ' #' => VERSION . minor, count= 1 )
0 commit comments