On Thu, Sep 4, 2025 at 9:56 AM Chet Ramey <chet.ra...@case.edu> wrote: > > The question is to whether to disallow it immediately or wait until there > is an assignment.
Disallowing it immediately is the right approach. $ declare -in foo bash: declare: cannot use -n with -i This makes the problem clear. > The problem > is that the arithmetic expansion is not helpful, since you can't use > namerefs to set the positional parameters. We can make that clearer. $ declare -n foo=0 bash: declare: `0': invalid variable name for name reference $ declare -n foo=1 bash: declare: `1': invalid variable name for name reference $ declare -n foo=not-valid bash: declare: `not-valid': invalid variable name for name reference $ declare -n bar $ bar=0 bash: `0': not a valid identifier $ bar=1 bash: `1': not a valid identifier $ bar=not-valid bash: `not-valid': not a valid identifier Maybe you could make the error message for assignment after declaration the same as the error message that declare gives, just removing "declare:". The current error message for that isn't bad though. If you want to implement another error message specific to setting the target of the nameref to an integer, that would be fine, but consider: $ 0=zero bash: 0=zero: command not found $ 1=one bash: 1=one: command not found Bash doesn't interpret the more straightforward attempt at that as an attempt at an assignment to begin with. Same deal with this, actually: $ not-valid=this bash: not-valid=this: command not found I wouldn't worry about it.