在bash取消设置只读变量 [英] Unset readonly variable in bash

查看:1735
本文介绍了在bash取消设置只读变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何取消设置只读变量在Bash的?

how to unset readonly variable in Bash?

$ readonly PI=3.14

$ unset PI
bash: PI: readonly variable

或者是不可能的?

or is it not possible?

推荐答案

其实,您可以不设置只读变量。但我必须提醒,这是一个哈克方法。加入这个答案,只能作为信息,不作为推荐。使用您自己的风险。经测试在Ubuntu 13.04,bash的4.2.45。

Actually, you can unset a readonly variable. but I must warn that this is a hacky method. Adding this answer, only as information, not as recommendation. Use at your own risk. Tested on ubuntu 13.04, bash 4.2.45.

该方法涉及知道有点庆典源$ C ​​$ C&放大器;它是从这个答案继承。

This method involves knowing a bit of bash source code & it's inherited from this answer.

$ 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

$

这篇关于在bash取消设置只读变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆