readonly — Mark a variable as read-only
Format
readonly [–p] [name[=value] …]
Description
readonly prevents
subsequent changes in the value
of any of the name arguments. Parameters
of the form:
name=value
assign value to name as
well as marking name read-only. If readonly is
called without arguments, it lists, with appropriate quoting, the
names you have set as read-only in the following format: Variable="value"
Options
- –p
- Displays export name=value pairs that,
when read by a shell, ensures the read-only status and values of variables.
The shell formats the output so it is suitable for reentry to the
shell as commands that achieve the same attribute-setting results.
Because it is not possible to change a read-only variable, you cannot source the output unless you go to a new shell.
Usage notes
readonly is a special built-in shell command.
Localization
readonly uses
the following localization environment variables:
- LANG
- LC_ALL
- LC_MESSAGES
- NLSPATH
See Localization for more information.
Exit values
- 0
- Successful completion
- 1
- An attempt to give read-only status to a variable that is already read-only
- 2
- Failure due to incorrect command-line argument
Portability
POSIX.2, X/Open Portability Guide.
The behavior given for calling readonly with no arguments is an extension of the POSIX standard.
Related information
alias, sh, typeset