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.

:- module program_name.
:- interface.
 
:- import_module io.
:- pred main(io::di, io::uo) is det.
 
:- implementation.
 
main(!IO) :-
    % The first argument is used as the program name if it is not otherwise
    % available.  (We could also have used the predicate io.progname_base/4
    % if we did not want path preceding the program name.)
    io.progname("", ProgName, !IO),
    io.print_line(ProgName, !IO).
 
:- end_module program_name.