-- TOC --
readonly命令也是一个bash的builtin,将变量设置为只读。
$ ABC=123
$ readonly ABC
$ ABC='abc'
bash: ABC: readonly variable
$ readonly KK='kk' # assign value while readonly
$ KK=123
bash: KK: readonly variable
-p
参数可以查看所有readonly变量:
$ readonly -p
declare -r ABC="123"
declare -r BASHOPTS="checkwinsize:cmdhist:complete_fullquote:expand_aliases:extglob:extquote:force_fignore:globasciiranges:histappend:interactive_comments:progcomp:promptvars:sourcepath"
declare -ar BASH_VERSINFO=([0]="5" [1]="0" [2]="17" [3]="1" [4]="release" [5]="x86_64-pc-linux-gnu")
declare -ir EUID="1000"
declare -r KK="kk"
declare -ir PPID="2088"
declare -r SHELLOPTS="braceexpand:emacs:hashall:histexpand:history:interactive-comments:monitor"
declare -ir UID="1000"
readonly变量也不能unset!
本文链接:https://cs.pynote.net/sf/linux/shell/202209151/
-- EOF --
-- MORE --