$ readonly currency=Dollars
Let’s try to remove the variable:
$ unset currencybash: unset: currency: cannot unset: readonly variable
If we try to change or remove the read-only variable in the script, it will give the following error:
#!/bin/bash AUTHOR="Ganesh Naik" readonly AUTHOR AUTHOR="John"
This will produce the following result:
/bin/sh: AUTHOR: This variable is read only.
Another technique is as follows:
declare -r variable=1 echo "variable=$variable" (( var1++ ))
The output after execution of the script is this:
line 4: variable: readonly variable