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.

with javascript_semantics
string cl2 = command_line()[2]
printf(1,"%s\n",cl2)                -- full path
printf(1,"%s\n",get_file_name(cl2)) -- eg test.exw or test.exe or test.htm
printf(1,"%s\n",get_file_base(cl2)) -- eg test
