How can I create a read-only variable?

In Bash, you can create a read-only variable

declare -r somevar='bla'

I tried to find something similar on POSIX sh, but the only thing that comes close is the phrase in the setdocumentation

[...] read-only variables cannot be reset.

How to create such a read-only variable?

+4
source share
1 answer

You can use readonly:

$ var="hello"
$ readonly var
$ echo $var
hello
$ var="bye"
sh: var: readonly variable
+5
source

All Articles