Currently, only the script's arguments are passed as positional
parameters. For compatibility reasons, $0 cannot be used to also pass the
script's filename, so I'm creating a new BASH_SCRIPT variable instead.
--- bash-5.1/doc/bash.1
+++ devel-5.1/doc/bash.1
@@ -1610,6 +1610,11 @@ matching the entire regular expression.
The element with index \fIn\fP is the portion of the
string matching the \fIn\fPth parenthesized subexpression.
.TP
+.B BASH_SCRIPT
+The name of the script currently being executed by \fBbash\fP, as specified on
+the command line.
+This is set before any startup files are executed for the script.
+.TP
.B BASH_SOURCE
An array variable whose members are the source filenames
where the corresponding shell function names in the
--- bash-5.1/doc/bashref.texi
+++ devel-5.1/doc/bashref.texi
@@ -5810,6 +5810,11 @@ matching the entire regular expression.
The element with index @var{n} is the portion of the
string matching the @var{n}th parenthesized subexpression.
+@item BASH_SCRIPT
+The name of the script currently being executed by bash, as specified on
+the command line. This is set before any startup files are executed for
+the script.
+
@item BASH_SOURCE
An array variable whose members are the source filenames where the
corresponding shell function names in the @code{FUNCNAME} array
--- bash-5.1/shell.c
+++ devel-5.1/shell.c
@@ -686,6 +686,7 @@ main (argc, argv, env)
else if (arg_index != argc && read_from_stdin == 0)
{
shell_script_filename = argv[arg_index++];
+ bind_variable ("BASH_SCRIPT", shell_script_filename, 0);
arg_index = bind_args (argv, arg_index, argc, 1); /* $1 ... $n */
}
else