This was already reported 12 and a half years ago, but there have not
been many replies:

  https://lists.gnu.org/archive/html/bug-bash/2010-12/msg00128.html

The issue seems to be caused by expr_streval() only checking for unbound
identifiers at this line:

  https://git.savannah.gnu.org/cgit/bash.git/tree/expr.c?h=devel#n1168
  if ((v == 0 || invisible_p (v)) && unbound_vars_is_error)

But then, after resolving the variable if the identifier is a array or
associative array variable, bash doesn't check that the result is set,
and just defaults to 0 if it isn't set at this line:

  https://git.savannah.gnu.org/cgit/bash.git/tree/expr.c?h=devel#n1219
  tval = (value && *value) ? subexpr (value) : 0;

This makes bash not trigger nounset if the identifier is a set
variable/array, even thought idenitifer[subscript] is not set.

  $ bash -uc 'printf %s\\n "$(( a ))"'
  bash: line 1: a: unbound variable
  $ bash -uc 'printf %s\\n "$(( a[1] ))"'
  bash: line 1: a: unbound variable
  $ a=xyz bash -uc 'printf %s\\n "$(( a[1] ))"'
  0
  $ bash -uc 'a=(1 2); let "a[10]"'
  0
  $ a=xyz bash -uc 'printf %s\\n "${a[1]}"'
  bash: line 1: a[1]: unbound variable
  $ bash -uc 'a=(1 2); printf %s\\n "${a[10]}"'
  bash: line 1: a[10]: unbound variable

o/
 emanuele6

Reply via email to