make $0 available to non-interactive shell startup files

This commit is contained in:
Chet Ramey
2021-07-28 10:27:04 -04:00
parent 6650b4de61
commit 6c84d09c19
6 changed files with 52 additions and 13 deletions
+18
View File
@@ -10777,3 +10777,21 @@ variables.c
- assign_in_env: if NAME is not a valid shell identifier, free it
after printing the error message and before returning. These are
the rest of the fixes from Siteshwar Vashisht <svashisht@redhat.com>
7/22
----
shell.c
- main: set dollar_vars[0] to shell_script_filename before calling
run_startup_files() in the non-interactive case. Restore it after
run_startup_files returns so we can get better error messages if
we can't open a script file. Suggested by several people, originally
by Marc Aurèle La France <tsi@tuyoix.net> back in 2/2021 (in a
different form) and most recently by Tapani Tarvainen
<bash@tapanitarvainen.fi>
7/28
----
trap.c
- any_signals_trapped: return that a signal is trapped only if it's
not ignored. This is an additional opportunity for optimization,
reported in https://bugzilla.redhat.com/show_bug.cgi?id=1981926
+10 -6
View File
@@ -701,9 +701,11 @@ below under
.BR "ARITHMETIC EVALUATION" .
If the value of the expression is non-zero, the return status is 0;
otherwise the return status is 1.
The \fIexpression\fP is expanded as if it were within double quotes,
but double quote characters in \fIexpression\fP are not special and
are removed.
The \fIexpression\fP
undergoes the same expansions
as if it were within double quotes,
but double quote characters in \fIexpression\fP are not treated specially
and are removed.
.TP
\fB[[\fP \fIexpression\fP \fB]]\fP
Return a status of 0 or 1 depending on the evaluation of
@@ -716,7 +718,7 @@ and filename expansion.
The shell performs tilde expansion, parameter and
variable expansion, arithmetic expansion, command substitution, process
substitution, and quote removal on those words
(as if the words were enclosed in double quotes).
(the expansions that would occur if the words were enclosed in double quotes).
Conditional operators such as \fB\-f\fP must be unquoted to be recognized
as primaries.
.if t .sp 0.5
@@ -3519,8 +3521,10 @@ and the substitution of the result. The format for arithmetic expansion is:
.PP
The
.I expression
is treated as if it were within double quotes, but a double quote
inside the parentheses is not treated specially.
undergoes the same expansions
as if it were within double quotes,
but double quote characters in \fIexpression\fP are not treated specially
and are removed.
All tokens in the expression undergo parameter and variable expansion,
command substitution, and quote removal.
The result is treated as the arithmetic expression to be evaluated.
+8 -5
View File
@@ -1127,8 +1127,9 @@ done
The arithmetic @var{expression} is evaluated according to the rules
described below (@pxref{Shell Arithmetic}).
The @var{expression} is expanded as if it were within double quotes,
but double quote characters in @var{expression} are not special and
The @var{expression} undergoes the same expansions
as if it were within double quotes,
but double quote characters in @var{expression} are not treated specially
are removed.
If the value of the expression is non-zero, the return status is 0;
otherwise the return status is 1.
@@ -1150,7 +1151,7 @@ and filename expansion.
The shell performs tilde expansion, parameter and
variable expansion, arithmetic expansion, command substitution, process
substitution, and quote removal on those words
(as if the words were enclosed in double quotes).
(the expansions that would occur if the words were enclosed in double quotes).
Conditional operators such as @samp{-f} must be unquoted to be recognized
as primaries.
@@ -2539,8 +2540,10 @@ and the substitution of the result. The format for arithmetic expansion is:
$(( @var{expression} ))
@end example
The @var{expression} is treated as if it were within double quotes, but
a double quote inside the parentheses is not treated specially.
The @var{expression} undergoes the same expansions
as if it were within double quotes,
but double quote characters in @var{expression} are not treated specially
and are removed.
All tokens in the expression undergo parameter and variable expansion,
command substitution, and quote removal.
The result is treated as the arithmetic expression to be evaluated.
+14
View File
@@ -694,10 +694,24 @@ main (argc, argv, env)
/* The startup files are run with `set -e' temporarily disabled. */
if (locally_skip_execution == 0 && running_setuid == 0)
{
char *t;
old_errexit_flag = exit_immediately_on_error;
exit_immediately_on_error = 0;
/* Temporarily set $0 while running startup files, then restore it so
we get better error messages when trying to open script files. */
if (shell_script_filename)
{
t = dollar_vars[0];
dollar_vars[0] = exec_argv0 ? savestring (exec_argv0) : savestring (shell_script_filename);
}
run_startup_files ();
if (shell_script_filename)
{
free (dollar_vars[0]);
dollar_vars[0] = t;
}
exit_immediately_on_error += old_errexit_flag;
}
+1 -1
View File
@@ -1,4 +1,4 @@
BUILD_DIR=/usr/local/build/chet/bash/bash-current
BUILD_DIR=/usr/local/build/bash/bash-current
THIS_SH=$BUILD_DIR/bash
PATH=$PATH:$BUILD_DIR
+1 -1
View File
@@ -569,7 +569,7 @@ any_signals_trapped ()
register int i;
for (i = 1; i < NSIG; i++)
if (sigmodes[i] & SIG_TRAPPED)
if ((sigmodes[i] & SIG_TRAPPED) && (sigmodes[i] & SIG_IGNORED) == 0)
return i;
return -1;
}