Open System Services Shell and Utilities Reference Manual (G06.29+, H06.08+, J06.03+)
User Commands (p - r) readonly(1)
NAME
readonly - Sets environment variables as read only
SYNOPSIS
readonly [name[=value ...]]
readonly -p
FLAGS
-p Writes to standard output the names and values of all read-only variables.
DESCRIPTION
The names and assigned values of environmental variables specified as name and value are
marked as read only and cannot be changed by subsequent assignment.
If -p is specified, readonly displays a list of the names and values of all read-only variables. The
shell formats the output, including the proper use of quoting, so that is it suitable for reinput to
the shell as commands that achieve the same attribute-setting results. The -p flag allows portable
access to the values that can be saved and then later restored by using, for example, a . (dot)
script.
EXAMPLES
1. In the following series of commands the variable x is made read only and the read only
status is tested:
x=3
readonly x
x=5
The last command in the above series results in the following error message:
x: is read only
NOTES
• Parameter assignment lists that precede the command remain in effect when the com-
mand completes.
• I/O redirections are processed after parameter assignments.
• Errors cause a script that contains the commands so marked to abort.
• Words in the format of a parameter assignment are expanded with the same rules as a
parameter assignment. This means that ˜ (tilde) substitution is performed after the =
(equal sign). Word splitting and filename generation are not performed.
The readonly command is a shell built-in command. It differs from the regular commands in that
it does not open a new shell process when it executes.
A general discussion of shell built-in commands and a list of the OSS shell built-in commands
are in the reference page for sh(1).
RELATED INFORMATION
Commands: sh(1).
527188-021 Hewlett-Packard Company 7−49