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 Checkit {
      Declare GetModuleFileName Lib "kernel32.GetModuleFileNameW"  {Long hModule, &lpFileName$, Long nSize}
      a$=string$(chr$(0), 260)
      namelen=GetModuleFileName(0, &a$, 260)
      a$=left$(a$, namelen)
      \\ normally m2000.exe is the caller of m2000.dll, the activeX script language
      Print Mid$(a$, Rinstr(a$, "\")+1)="m2000.exe" 
}
Checkit
\\ command$ return the file's path plus name of script
\\ we can use edit "callme.gsb" to paste these, and use USE callme to call it from M2000 console.
Module SayIt {
      Show
      Print command$
      a$=key$
}
SayIt
 