Skip to main content
dbmathis

1 year ago

Unset readonly variable in bash

While going through the bash scripting course for system admins I saw that it's not possible to unset a readonly variable. I know that in general and for all practical purposes it's true, however, naturally,  I immediately set out on a mission to do what can't be done. :).

I ended up on stack exchange and found the following, which actually did work for me to unset a readonly variable. I was hoping that someone could help to break down how this works. This is more of a fun distraction than a serious question. I thought it was worth sharing.


$ readonly PI=3.14

$ unset PI

-bash: unset: PI: cannot unset: readonly variable

$ cat << EOF| sudo gdb

attach $$

call unbind_variable("PI")

detach

EOF

$ echo $PI

$



Image of keiththomps
keiththomps
1 year ago
Clever :)