]> git.ipfire.org Git - thirdparty/bash.git/commitdiff
make $0 available to non-interactive shell startup files
authorChet Ramey <chet.ramey@case.edu>
Wed, 28 Jul 2021 14:27:04 +0000 (10:27 -0400)
committerChet Ramey <chet.ramey@case.edu>
Wed, 28 Jul 2021 14:27:04 +0000 (10:27 -0400)
CWRU/CWRU.chlog
doc/bash.1
doc/bashref.texi
shell.c
tests/RUN-ONE-TEST
trap.c

index e68a40fbe83abf61d09adc79615a735f4ad1be23..4765a62aec0672e08be5d59b6bb648637c0bfeb7 100644 (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
index df0658da9a4a1800cd1c121685c902db58dbaa1a..3f4461c4b5717657c4c92d2fb2a6de71914d7f4d 100644 (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.
index 5805c588a1f00dbf55d318c781089e3badeb2b3d..aa77dda4c73e0bf41631f751dcd0065d20e31094 100644 (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.
diff --git a/shell.c b/shell.c
index ce8087f77b86555891dace28dce8e18f8c3c14f0..82c4985aad8abca62f234804ae9cd6ceb2165c17 100644 (file)
--- a/shell.c
+++ b/shell.c
@@ -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;
     }
 
index 0b06381072414283266cf5d055a42ac14b9b6da6..c8bef8dd12533217b1b65fc20d00f3d1cc1b81e7 100755 (executable)
@@ -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
 
diff --git a/trap.c b/trap.c
index dd1c9a56fae7c08a17f24995c8bdd05a0dc87ac0..080ae40ff9a12861eef493a528df93cfce156b14 100644 (file)
--- a/trap.c
+++ b/trap.c
@@ -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;
 }