declaredeclare inside a function doesn't work as expected. I needed read only-only global variables declared in a function. I tried this inside a function but it didn't work:
declare -r MY_VAR=1 But this didn't work. Using readonly Using the readonly command worked for medid:
func() { readonly MY_VAR=1 } func echo $MY_VAR MY_VAR=2 This will print 1 and gives and give the error MY_VAR"MY_VAR: readonly variablevariable" for the second assignment.
Regards, Kfir