[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
readonly assignment should exit when non-interactive
From: |
llattanzi+bash |
Subject: |
readonly assignment should exit when non-interactive |
Date: |
Fri, 02 Jul 2004 15:16:19 -0700 (PDT) |
Configuration Information [Automatically generated, do not change]:
Machine: powerpc
OS: darwin8.0
Compiler: gcc
Compilation CFLAGS: -arch i386 -arch ppc -g -Os -pipe -no-cpp-precomp
-arch i386 -arch ppc -pipe -DPROGRAM='bash' -DCONF_HOSTTYPE='powerpc'
-DCONF_OSTYPE='darwin8.0' -DCONF_MACHTYPE='powerpc-apple-darwin8.0'
-DCONF_VENDOR='apple' -DSHELL -DHAVE_CONFIG_H -DMACOSX -I.
-I/SourceCache/bash/bash-30/bash
-I/SourceCache/bash/bash-30/bash/include
-I/SourceCache/bash/bash-30/bash/lib -arch i386 -arch ppc -g -Os -pipe
-no-cpp-precomp -arch i386 -arch ppc -pipe
uname output: Darwin stderr.apple.com 8.0.0b1 Darwin Kernel Version
8.0.0b1: Mon Jun 21 20:09:53 PDT 2004;
root:xnu/xnu-634.obj~2/RELEASE_PPC Power Macintosh powerpc
Machine Type: powerpc-apple-darwin8.0
Bash Version: 2.05b
Patch Level: 0
Release Status: release
Description:
If the current command has another special builtin errors from
a temporary environment assignment are ignored
Repeat-By:
cat > test.sh <<EOF
readonly ro1=foo
ro1=bar readonly ro2=snafu
printf "Did we get here?\n"
EOF
sh test.sh
Fix:
Index: bash/execute_cmd.c
===================================================================
RCS file: /cvs/root/bash/bash/execute_cmd.c,v
retrieving revision 1.1.1.5
diff -u -d -b -w -r1.1.1.5 execute_cmd.c
--- execute_cmd.c 2003/04/05 08:00:25 1.1.1.5
+++ execute_cmd.c 2004/07/02 21:44:41
@@ -2708,6 +2708,14 @@
if (builtin_is_special)
special_builtin_failed = 1;
}
+ /* In POSIX mode, if there are assignment errors preceding
+ a special builtin, a non-interactive shell shall exit. */
+ if (posixly_correct && interactive_shell==0 &&
+ builtin_is_special && temporary_env_errors)
+ {
+ last_command_exit_value = EXECUTION_FAILURE;
+ jump_to_top_level(FORCE_EOF);
+ }
/* In POSIX mode, if there are assignment statements preceding
a special builtin, they persist after the builtin
completes. */
Index: bash/variables.c
===================================================================
RCS file: /cvs/root/bash/bash/variables.c,v
retrieving revision 1.1.1.5
diff -u -d -b -w -r1.1.1.5 variables.c
--- variables.c 2003/04/05 08:00:27 1.1.1.5
+++ variables.c 2004/07/02 21:44:41
@@ -101,6 +101,8 @@
/* The set of shell assignments which are made only in the environment
for a single command. */
HASH_TABLE *temporary_env = (HASH_TABLE *)NULL;
+/* Count of all errors processing temporary_env assignments */
+int temporary_env_errors = 0;
/* Some funky variables which are known about specially. Here is where
"$*", "$1", and all the cruft is kept. */
@@ -1889,6 +1891,9 @@
name = savestring (string);
value = (char *)NULL;
+ if (temporary_env == 0) /* force creation so that
temporary_env_errors is reset later */
+ temporary_env = hash_create (TEMPENV_HASH_BUCKETS);
+
if (name[offset] == '=')
{
name[offset] = 0;
@@ -1899,6 +1904,7 @@
if (readonly_p (var))
err_readonly (name);
free (name);
+ temporary_env_errors++;
return (0);
}
@@ -1909,9 +1915,6 @@
free (temp);
}
- if (temporary_env == 0)
- temporary_env = hash_create (TEMPENV_HASH_BUCKETS);
-
var = hash_lookup (name, temporary_env);
if (var == 0)
var = make_new_variable (name, temporary_env);
@@ -2658,6 +2661,7 @@
hash_flush (temporary_env, pushf);
hash_dispose (temporary_env);
temporary_env = (HASH_TABLE *)NULL;
+ temporary_env_errors = 0;
array_needs_making = 1;
Index: bash/variables.h
===================================================================
RCS file: /cvs/root/bash/bash/variables.h,v
retrieving revision 1.1.1.8
diff -u -d -b -w -r1.1.1.8 variables.h
--- variables.h 2003/04/05 08:00:27 1.1.1.8
+++ variables.h 2004/07/02 21:44:42
@@ -198,6 +198,7 @@
extern HASH_TABLE *shell_functions;
extern HASH_TABLE *temporary_env;
+extern int temporary_env_errors;
extern int variable_context;
extern char *dollar_vars[];
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- readonly assignment should exit when non-interactive,
llattanzi+bash <=