declare的法;
定义环境变量:declare -x 变量名
修改环境变量为本地变量: declare +x 环境变量名
使变量变为可读:declare -r 变量名
[[email protected] opt]# bb=10 [[email protected] opt]# declare -r bb //把变量变为可读(不能修改和删除) [[email protected] opt]# bb=20 bash: bb: readonly variable [[email protected] opt]# unset bb bash: unset: bb: cannot unset: readonly variable [[email protected] opt]#
使变量变为可读的另一种方法: readonly 变量名
[[email protected] opt]# cc=20 [[email protected] opt]# readonly cc [[email protected] opt]# cc=30 bash: cc: readonly variable [[email protected] opt]# unset cc bash: unset: cc: cannot unset: readonly variable [[email protected] opt]#
时间: 2024-12-25 17:11:29