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:

  1. Variables with values at the time they were output do not have the readonly attribute set.
  2. 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 -p option 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

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