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")



$ echo $PI


  • post-author-pic
    Keith T

    Clever :)

Looking For Team Training?

Learn More