素材巴巴 > 程序开发 >

readonly只读变量的设置与取消

程序开发 2023-09-10 07:36:45

source /etc/profile 出现 bash:PROMPT-COMMAND: 只读变量
利用unset命令是无法删除只读变量的

 如果需要取消设置的只读变量需要用到gdb命令可以使用rpm -q gdb查看下自己系统中是否有该命令,没有的话可以yum -y install gdb安装下

下载好可以使用下面的方法取消下

[root@zyf ~]# cat < attach $$
 > call unbind_variable("name")
 > detach
 > EOF
 GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-120.el7
 Copyright (C) 2013 Free Software Foundation, Inc.
 License GPLv3+: GNU GPL version 3 or later 
 This is free software: you are free to change and redistribute it.
 There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
 and "show warranty" for details.
 This GDB was configured as "x86_64-redhat-linux-gnu".
 For bug reporting instructions, please see:
 .
 (gdb) Attaching to process 15886
 Reading symbols from /usr/bin/bash...Reading symbols from /usr/bin/bash...(no debugging symbols found)...done.
 (no debugging symbols found)...done.
 Reading symbols from /lib64/libtinfo.so.5...Reading symbols from /lib64/libtinfo.so.5...(no debugging symbols found)...done.
 (no debugging symbols found)...done.
 Loaded symbols for /lib64/libtinfo.so.5
 Reading symbols from /lib64/libdl.so.2...(no debugging symbols found)...done.
 Loaded symbols for /lib64/libdl.so.2
 Reading symbols from /lib64/libc.so.6...(no debugging symbols found)...done.
 Loaded symbols for /lib64/libc.so.6
 Reading symbols from /lib64/ld-linux-x86-64.so.2...(no debugging symbols found)...done.
 Loaded symbols for /lib64/ld-linux-x86-64.so.2
 Reading symbols from /lib64/libnss_files.so.2...(no debugging symbols found)...done.
 Loaded symbols for /lib64/libnss_files.so.2
 0x00007fa89ba38a3c in waitpid () from /lib64/libc.so.6
 Missing separate debuginfos, use: debuginfo-install bash-4.2.46-31.el7.x86_64
 (gdb) $1 = 0
 (gdb) Detaching from program: /usr/bin/bash, process 15886
 [Inferior 1 (process 15886) detached]
 (gdb) quit
 

上面的执行完成后再重新对name进行赋值

[root@zyf ~]# name=lisi
 [root@zyf ~]# echo $name
 lisi
 

 可以看到已经可以重新对name变量进行赋值了


标签:

素材巴巴 Copyright © 2013-2021 http://www.sucaibaba.com/. Some Rights Reserved. 备案号:备案中。