The task is to programmatically obtain the name used to invoke the program. (For example determine whether the user ran "python hello.py", or "python hellocaller.py", a program importing the code from "hello.py".)

Sometimes a multiline shebang is necessary in order to provide the script name to a language's internal ARGV.

See also Command-line arguments

Examples from GitHub.

const std = @import("std");
 
const debug = std.debug;
const heap = std.heap;
const process = std.process;
 
pub fn main() !void {
    var args = process.args();
 
    const program_name = try args.next(heap.page_allocator) orelse unreachable;
    defer heap.page_allocator.free(program_name);
 
    debug.warn("{}\n", .{program_name});
}