【Linux】一步一步学Linux——readonly命令(219)

00. 目录

01. 命令概述

readonly命令用于定义只读shell变量和shell函数。readonly命令的选项-p可以输出显示系统中所有定义的只读变量。

02. 命令格式

用法:
	readonly [-aAf] [name[=value] ...]
	readonly -p

03. 常用选项

-f: 定义shell函数
-a: 定义索引数组变量
-A: 定义关联数组变量
-p: 显示系统中全部只读变量和函数列表

04. 参考示例

4.1 显示只读变量

[root@localhost ~]# readonly 
declare -r BASHOPTS="checkwinsize:cmdhist:expand_aliases:extglob:extquote:force_fignore:histappend:interactive_comments:login_shell:progcomp:promptvars:sourcepath"
declare -ir BASHPID
declare -r BASH_COMPLETION_COMPAT_DIR="/etc/bash_completion.d"
declare -ar BASH_VERSINFO='([0]="4" [1]="2" [2]="46" [3]="2" [4]="release" [5]="x86_64-redhat-linux-gnu")'
declare -ir EUID="0"
declare -ir PPID="31241"
declare -r SHELLOPTS="braceexpand:emacs:hashall:histexpand:history:interactive-comments:monitor"
declare -ir UID="0"
[root@localhost ~]# 

4.2 定义只读变量并初始化

[root@localhost ~]# readonly AA="邓进"
[root@localhost ~]# echo $AA
邓进
[root@localhost ~]# AA="程序员"
-bash: AA: readonly variable
[root@localhost ~]# 

4.3 显示系统中全部只读变量和函数列表

[root@localhost ~]# readonly -p
declare -r AA="邓进"
declare -ir BASHPID
declare -r BASH_COMPLETION_COMPAT_DIR="/etc/bash_completion.d"
declare -ir EUID="0"
declare -ir PPID="31241"
declare -r SHELLOPTS="braceexpand:emacs:hashall:histexpand:history:interactive-comments:monitor"
declare -ir UID="0"
[root@localhost ~]# 

05. 附录

参考:【Linux】一步一步学Linux系列教程汇总

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值