* On 2/13/22 10:50 PM, Chet Ramey wrote: > Hmmmm. So what you're proposing is that `shopt -u compat43' if compat43 is > not set should not reset the compatibility level to the current version. > OK. > > I think we could do this by interrogating $BASH_COMPAT after unsetting the > appropriate compat_NN option. > > Or maybe leaving shell_compatibility_level alone if it's > 44 (the last > compat_NN option) and <= DEFAULT_COMPATIBILITY_LEVEL (the current version) > instead of unconditionally setting it to DEFAULT_COMPATIBILITY_LEVEL. But > then you'd be required to unset BASH_COMPAT to get back to the current > compatibility level, which is supported now but not required.
The easiest way to do this would be to check if the old value matches the new one and in case both were unset, just do nothing. However, looking at the source, I understand that this is not easily possible, since the old value is overwritten in toggle_shopts() immediately and only the new mode passed to the registered set_func fptr. I'd refactor this to also give it the old value and just turn set_compatibility_value() into a no-op if (!old_val) && (!new_val). Mihai
OpenPGP_signature
Description: OpenPGP digital signature