← 返回命令列表

Linux command

readonly 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Make variable readonly

readonly [VAR]="[value]"

Make existing variable readonly

readonly [VAR]

List readonly variables

readonly

Make function readonly

readonly -f [function_name]

Make array readonly

readonly -a [ARRAY]

说明

readonly is a shell builtin that marks variables or functions as read-only, preventing modification or unsetting. Useful for constants and protecting configuration values.

参数

-p
Print readonly variables.
-f
Make functions readonly.
-a
Make arrays readonly.
-A
Make associative arrays readonly.

FAQ

What is the readonly command used for?

readonly is a shell builtin that marks variables or functions as read-only, preventing modification or unsetting. Useful for constants and protecting configuration values.

How do I run a basic readonly example?

Run `readonly [VAR]="[value]"` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -p do in readonly?

Print readonly variables.