2023-07-05 10:53:12 +02:00
|
|
|
# The readonly builtin command
|
|
|
|
|
|
|
|
## Synopsis
|
|
|
|
|
|
|
|
readonly [-p] [-a] [-A] [-f] [NAME[=VALUE] ...]
|
|
|
|
|
|
|
|
## Description
|
|
|
|
|
|
|
|
The `readonly` builtin command is used to mark variables or functions as
|
2024-03-30 20:09:26 +01:00
|
|
|
read-only, which means unchangeable. This implies that it can't be
|
2023-07-05 10:53:12 +02:00
|
|
|
unset anymore. A `readonly` variable may not be redefined in child
|
|
|
|
scopes. A readonly global may not be redefined as a function local
|
|
|
|
variable. Simple command environment assignments may not reference
|
|
|
|
readonly variables.
|
|
|
|
|
|
|
|
### Options
|
|
|
|
|
2024-10-08 06:00:17 +02:00
|
|
|
|Option|Description|
|
|
|
|
|-|-|
|
|
|
|
|`-a`|refer to normal arrays|
|
|
|
|
|`-A`|refer to associative arrays|
|
|
|
|
|`-f`|refer to functions|
|
|
|
|
|`-p`|print all read-only variables or functions, `-a`, `-A` and `-f` can be used to filter. The output is reusable as input|
|
2023-07-05 10:53:12 +02:00
|
|
|
|
|
|
|
An argument of `--` disables further option processing.
|
|
|
|
|
|
|
|
### Return status
|
|
|
|
|
2024-10-08 06:00:17 +02:00
|
|
|
|Status|Reason|
|
|
|
|
|-|-|
|
|
|
|
|0|no error|
|
|
|
|
|!=0|invalid option|
|
|
|
|
|!=0|invalid combination of options|
|
|
|
|
|!=0|a given `NAME` is invalid|
|
2023-07-05 10:53:12 +02:00
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
## Portability considerations
|
|
|
|
|
|
|
|
- in POSIX(r), only the `-p` option is specified
|
|
|
|
|
|
|
|
## See also
|
|
|
|
|
2024-01-29 02:07:56 +01:00
|
|
|
- [declare](../../commands/builtin/declare.md)
|
|
|
|
- [unset](../../commands/builtin/unset.md)
|