readonly

mark KornShell variable as read-only 

KornShell Built-in


SYNOPSIS

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 the KornShell variable name as well as marking name read-only. If readonly is called without arguments it lists, with appropriate quoting, the KornShell variables set as read-only. The following format is used:

Variable="value"

This format is suitable for reading by a shell script, but to ensure the portability of read-only access, the -p option should be used.

Options

-p 

displays read-only variables in the format:

readonly name=value

This ensures portability when this output is used as input to a shell.

Note:

Normally, this output is captured in a file which is then sourced to reproduce the current environment. Because trying to change a read-only variable fails with an error, you can't successfully source the output unless you go to a new shell.


DIAGNOSTICS

Possible exit status values:

0 

Successful completion.

1 

An attempt to give read-only status to a variable which is already read-only.

2 

Failure due to invalid command line argument.


PORTABILITY

POSIX.2. x/OPEN Portability Guide 4.0. Windows 10. Windows Server 2016. Windows Server 2019. Windows 11. Windows Server 2022. Windows Server 2025. readonly is a built-in command of the Bourne Shell and KornShell on UNIX systems.

The behavior of readonly when called with no arguments is an extension to the POSIX and XPG standards.


NOTE

This is a special built-in command of the MKS KornShell.


AVAILABILITY

PTC MKS Toolkit for Power Users
PTC MKS Toolkit for System Administrators
PTC MKS Toolkit for Developers
PTC MKS Toolkit for Interoperability
PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition
PTC Windchill Requirements and Validation


SEE ALSO

Commands:
alias, sh, typeset


PTC MKS Toolkit 10.5 Documentation Build 40.