# readonly

## PROLOG



           This manual page is part of the POSIX Programmer's Manual.  The
           Linux implementation of this interface may differ (consult the
           corresponding Linux manual page for details of Linux behavior), or
           the interface may not be implemented on Linux.
    


## NAME



           readonly — set the readonly attribute for variables
    


## SYNOPSIS



           readonly name**[** =_word_**]**...
    
           readonly -p
    


## DESCRIPTION



           The variables whose _name_ s are specified shall be given the
           _readonly_ attribute. The values of variables with the _readonly_
           attribute cannot be changed by subsequent assignment, nor can
           those variables be unset by the _unset_ utility. If the name of a
           variable is followed by =_word_ , then the value of that variable
           shall be set to _word_.
    
           The _readonly_ special built-in shall support the Base Definitions
           volume of POSIX.1‐2017, _Section 12.2_ , _Utility Syntax Guidelines_.
    
           When **-p** is specified, _readonly_ writes to the 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 is 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.
    


## OPTIONS



           See the DESCRIPTION.
    


## OPERANDS



           See the DESCRIPTION.
    


## STDIN



           Not used.
    


## INPUT FILES



           None.
    


## ENVIRONMENT VARIABLES



           None.
    


## ASYNCHRONOUS EVENTS



           Default.
    


## STDOUT



           See the DESCRIPTION.
    


## STDERR



           The standard error shall be used only for diagnostic messages.
    


## OUTPUT FILES



           None.
    


## EXTENDED DESCRIPTION



           None.
    


## EXIT STATUS



            0    All _name_ operands were successfully marked readonly.
    
           >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._
    


## APPLICATION USAGE



           None.
    


## EXAMPLES



           readonly HOME PWD
    


## RATIONALE



           Some historical shells preserve the _readonly_ attribute across
           separate invocations. This volume of POSIX.1‐2017 allows this
           behavior, but does not require 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(1p) for a description of the no-
           argument and **-p** output cases and a related example.
    
           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'' (spoofing 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.
    


## FUTURE DIRECTIONS



           None.
    


* * *