Even if help local does not mention this in Bash 3.x, local can accept the same parameters as declare (at least Bash 4.3.30, this documentation supervision has been fixed).
So you can just do:
local -r var=val
However, declare inside the function behaves like local by default, as the comments indicate ruakh, so your first attempt should also have been to create a read-only local variable.
In Bash 4.2 and later, you can override this with the declare -g option to create a global variable even from within the function (Bash 3.x does not support this.)
source share