LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to remove readonly variable? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-remove-readonly-variable-636847/)

hocheetiong 04-21-2008 02:30 PM

How to remove readonly variable?
 
Hi,

# var1=super
# var1=

1.first i assign var1=super, than i assign var1 to nothing.


# var1=super
# readonly var1
# var1=
-bash: var1: readonly variable
# unset var1
-bash: unset: var1: cannot unset: readonly variable


2. Now i assign var1 as readonly variable, than if i really want to change or remove this variable how to do?


Thank.

colucix 04-21-2008 04:04 PM

Quote:

Originally Posted by hocheetiong (Post 3128214)
2. Now i assign var1 as readonly variable, than if i really want to change or remove this variable how to do?

Don't declare it as readonly. Once you've set a variable as readonly you can't do anything but kill the shell.

The only chance is to use readonly variables in a subshell. In this case the variable is local to the subshell and the parent shell is not aware of its existence:
Code:

( var=3; readonly var; echo $var )
var=5
echo $var



All times are GMT -5. The time now is 07:40 PM.