How can we check under if whether a variable is readonly or not? Please Explain with Examples
How can we check whether a variable is readonly or not in linux
275 Views Asked by Aditya Purusharthi At
2
There are 2 best solutions below
0

If you type the command readonly without arguments, it will print the list of the readonly variables. So you can write something like this:
readonly PI=3.14
PO=3.14
if [ "$(readonly | grep -w PI)" != "" ] ; then echo read-only ; else echo not read-only ; fi
if [ "$(readonly | grep -w PO)" != "" ] ; then echo read-only ; else echo not read-only ; fi
which will result in the following output:
read-only
not read-only
You do not provide any information of what are you talking about, but I guess you want to check a variable in bash.
If that is the case, this post may help you: Test if a variable is read-only
In future questions, I suggest you to provide more information about the environment you are working on.