On Mon, Oct 14, 2024 at 2:57 AM Chet Ramey <[email protected]> wrote:
>
> I'll consider it, but I'm not eager to carve out more exceptions for
> `set -u'.
Checking for unbound_vars_is_error can be done earliest if you worry
about additional runtime weight. It makes the code for disabled `set
-u` instances optimal by default even just by theory. That way the
number of added exceptions would only matter to people who care about
using `set -u`.
--
konsolebox
diff --git a/subst.c b/subst.c
index 251eafaf..5e906c10 100644
--- a/subst.c
+++ b/subst.c
@@ -10142,9 +10142,9 @@ parameter_brace_expand (char *string, size_t *indexp,
int quoted, int pflags, in
/* All the cases where an expansion can possibly generate an unbound
variable error. */
- if (want_substring || want_patsub || want_casemod || c == '@' || c == '#' ||
c == '%' || c == RBRACE)
- {
- if (var_is_set == 0 && unbound_vars_is_error && ((name[0] != '@' &&
name[0] != '*') || name[1]) && all_element_arrayref == 0)
+ if (unbound_vars_is_error)
+ if (want_substring || want_patsub || want_casemod || c == '@' &&
!want_attributes || c == '#' || c == '%' || c == RBRACE)
+ if (var_is_set == 0 && ((name[0] != '@' && name[0] != '*') || name[1])
&& all_element_arrayref == 0)
{
set_exit_status (EXECUTION_FAILURE);
err_unboundvar (name);
@@ -10153,7 +10153,6 @@ parameter_brace_expand (char *string, size_t *indexp,
int quoted, int pflags, in
free (name);
return (interactive_shell ? &expand_wdesc_error :
&expand_wdesc_fatal);
}
- }
/* If this is a substring spec, process it and add the result. */
if (want_substring)