Linux readonly

1. 概念
readonly在shell脚本中,用来标记变量是只读的,后续执行过程中就不能对其值进行改变,这个用来定义一些常量类的变量. 如果对其进行重新赋值,会提示错误

[root@localhost etc]# hours_per_day=24
[root@localhost etc]# echo $hours_per_day
24
[root@localhost etc]# readonly hours_per_day
[root@localhost etc]# hours_per_day=0
-bash: hours_per_day: readonly variable

2. 重置readonly变量
如何将变量调整为"非只读"状态呢?我们可以试试unset命令.

[root@localhost etc]# unset hours_per_day
-bash: unset: hours_per_day: cannot unset: readonly variable
[root@localhost etc]#

从上面可以得知unset是不能够将readonly的变量重置的.

下面是一个非常规的操作(注意:不推荐使用)


[root@localhost etc]# cat << EOF| sudo gdb
attach $$
call unbind_variable("hours_per_day")
detach
EOF

posted @ 2022-12-22 19:21  牧之丨  阅读(182)  评论(0编辑  收藏  举报