bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bash 5.1: Make shell_script_filename available to startup files


From: Marc Aurèle La France
Subject: Re: Bash 5.1: Make shell_script_filename available to startup files
Date: Fri, 16 Feb 2024 14:16:16 -0700 (Mountain Standard Time)
User-agent: Alpine 2.20 (WNT 67 2015-01-07)

On Mon, 2021-Feb-01, Marc Aurèle La France wrote:

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


Yes, it's been three years, but...

Withdrawn. I can accomplish the same thing by capturing $_ early on, before it gets clobbered by whatever.

Marc.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]