1

I can declare a bash variable as read only:

var=myname
declare -r var

and then when I try to change the value :

var=anothername

I get (in zsh for example)

>>read-only variable: var

How can I "undeclare" or unset this variable?

Braiam
  • 1
  • 11
  • 47
  • 78
alonisser
  • 11,542
  • 21
  • 85
  • 139
  • 2
    possible duplicate of [Unset readonly variable in bash](http://stackoverflow.com/questions/17397069/unset-readonly-variable-in-bash) – dg99 Jan 15 '15 at 15:49

2 Answers2

2

You can't in bash, readonly means you can't change that variable in anyway, including getting rid of it.

Paul Evans
  • 27,315
  • 3
  • 37
  • 54
2

I found this here unset:

$ cat << EOF| sudo gdb
attach $$
call unbind_variable("var")
detach
EOF
Community
  • 1
  • 1
Aman
  • 1,157
  • 7
  • 13
  • 1
    a very UGLY solution.. using gdb for that. Does work and answer the question. But I would never use this in production code.. – alonisser Jan 15 '15 at 17:08