Shell | type readonly |
zsh | readonly is a reserved word |
bash | readonly is a shell builtin |
dash | readonly is a special shell builtin |
tcsh | readonly is a shell builtin |
mksh | readonly is a special shell builtin |
pkdksh | readonly is a special shell builtin |
readonly
命令用于定义只读变量
。
readonly variable=value
readonly -p
如果想要防止修改变量的值,就可以使用此命令,一旦被修改就会报错。
注意:被readonly
修饰的变量,在定义变量的时候,就必须赋值,否值以后就没有机会赋值了。
示例:
readonly a="abcdefg";
打印出所有的readonly
变量。