READONLY(1P)
π PROLOG π
ok so bestie, real talk before we dive in: this manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ β like, consult the corresponding Linux manual page for the deets on Linux behavior, okay? Or honestly? The interface might not even be implemented on Linux at all. π Not everything makes it to the party.
β¨ NAME β¨
readonly β set the readonly attribute for variables π
πΈ SYNOPSIS πΈ
readonly name[=word]...
readonly -p
π¦ DESCRIPTION π¦
okay so here's the whole vibe. The variables whose names are specified shall be given the readonly attribute. And once a variable has that attribute? Bestie, it's locked in. The values of variables with the readonly attribute cannot be changed by subsequent assignment, and those variables cannot be unset by the unset utility. Like, it's giving "you said it, now you live with it" energy. π
But! If the name of a variable is followed by =word, then the value of that variable shall be set to word. So you can assign and lock at the same time. Efficient queen behavior. π
The readonly special built-in shall support the Base Definitions volume of POSIX.1β2017, Section 12.2, Utility Syntax Guidelines. (iykyk)
When -p is specified, readonly writes to standard output the names and values of all read-only variables, in the following format:
"readonly %s=%s\n", <name>, <value>
if name is set, and
"readonly %s\n", <name>
if name is unset.
The shell shall format the output β including the proper use of quoting β so that it's suitable for reinput to the shell as commands that achieve the same value and readonly attribute-setting results in a shell execution environment in which:
- Variables with values at the time they were output do not have the readonly attribute set.
- Variables that were unset at the time they were output do not have a value at the time at which the saved output is reinput to the shell.
When no arguments are given, the results are unspecified. So like... don't count on it, bestie. π
β¨ OPTIONS β¨
See the DESCRIPTION. That's it, that's the whole section. β¨
π OPERANDS π
See the DESCRIPTION. Also just that. π
π STDIN π
Not used. She's not listening to you on this one. π
π INPUT FILES π
None. Zero. Nada. π
π§ ENVIRONMENT VARIABLES π§
None. The environment is not involved, bestie. β¨
β ASYNCHRONOUS EVENTS β
Default. Nothing special, just the standard behavior. π
πΈ STDOUT πΈ
See the DESCRIPTION. (Yes, again. It's all in there, I promise.) π
π¦ STDERR π¦
The standard error shall be used only for diagnostic messages. That's its whole job. π
π OUTPUT FILES π
None. She doesn't write files, she writes to stdout and that's it. β¨
π EXTENDED DESCRIPTION π
None. Nothing extra to say. Moving on, gorgeous. π
π₯ EXIT STATUS π₯
0β All name operands were successfully marked readonly. Slay. π>0β At least one name could not be marked readonly, or the-poption was specified and an error occurred. π
π CONSEQUENCES OF ERRORS π
Default.
The following sections are informative. (aka: the fun gossip section, not the rules section π)
π APPLICATION USAGE π
None. Nothing to add here. β¨
π EXAMPLES π
readonly HOME PWD
boom. locked. π
π RATIONALE π
okay so the tea β:
Some historical shells preserve the readonly attribute across separate invocations. This volume of POSIX.1β2017 allows this behavior, but does not require it. So it's giving "we see you, but we're not mandating it."
The -p option allows portable access to the values that can be saved and then later restored using, for example, a dot script. Also see the RATIONALE for export for a description of the no-argument and -p output cases and a related example. (Go read it, bestie, it's connected. π)
Read-only functions were considered, but they were omitted as not being historical practice or particularly useful. Furthermore, functions must not be read-only across invocations to preclude ``spoofing'' β and spoofing, for the record, is the term for the practice of creating a program that acts like a well-known utility with the intent of subverting the real intent of the user β of administrative or security-relevant (or security-conscious) shell scripts. So like, no fake besties pretending to be the real thing. π« Not on our watch.
β FUTURE DIRECTIONS β
None. The future is... unchanged. π
π SEE ALSO π
- Section 2.14, Special Built-In Utilities
- The Base Definitions volume of POSIX.1β2017, Section 12.2, Utility Syntax Guidelines
π COPYRIGHT π
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
and that's the whole page, bestie!! π«Ά this one came from IEEE/The Open Group, 2017, and it's the READONLY(1P) page β the POSIX Programmer's Manual one, not the Linux one, remember?? Now go forth and lock your variables. periodt. π
β¨
π¦ where this page comes from
- alpine 3.22: man-pages-posix 2017a-r0 Β· custom
- alpine 3.23: man-pages-posix 2017a-r0 Β· custom
- alpine 3.24: man-pages-posix 2017a-r0 Β· custom
- arch rolling: man-pages 6.19-1
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages-posix 2017a
- opensuse-leap 16.0: man-pages-posix 2017a-160000.4.1 Β· SUSE-IEEE
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms