Format
typeset ±f [tux] name
…
typeset [±lprtuxH]
[±iLRZ[number]]
[variable[=value] ….]
Description
Invoking typeset with
no options displays a list of all variables
and their attributes. This list is sorted by variable name and includes
quoting so that it can be reinput to the shell with the built-in command eval. When only arguments of the form +option are
specified, typeset displays a list of the
variables that have all specified attributes set. When only arguments
of the form –option are
present, typeset displays a list of all
the variables having all the specified attributes set, and also displays
their values.
When the f option is
used, typeset applies to functions; otherwise,
it applies to variables. For functions, the only other applicable
options are –t, –u and –x.
If
the command line contains at least one variable, the attributes of
each variable are changed. In
this case, parameters of the form –option turn
on the associated attributes. Parameters of the form +option turn
off the associated attributes. (Notice that, contrary to what you
might expect, - means on, and + means off.) Parameters
of the form variable=value turn
on the associated attributes and also assign value to variable.
When typeset is
invoked inside a function, a new instance of each variable is created.
After the function ends, each variable is restored to the value and
attributes it had before the function was called.
Options
- –f
- Specifies attributes of functions.
- –H
- Performs file mapping from POSIX to the host name.
- –i[number]
- Marks each variable as having an integer value, thus making arithmetic
faster. If number is given and is nonzero,
the output base of each variable is number.
The default is decimal.
- –l
- Converts uppercase characters to lowercase in any value assigned
to a variable. If the –u option is currently
turned on, this option turns it off.
- –p
- Writes output to the coprocess. This option is not currently implemented.
- –r
- Makes each variable read-only. See readonly.
- –t
- Tags each variable. Tags are user-defined, and have no meaning
to the shell. For functions with the –f option,
this turns on the xtrace option. See set for
a discussion of the xtrace option.
- –u
- Converts lowercase characters to uppercase in any value assigned
to a variable. If the –l option is currently
turned on, this option turns it off.
When used with –f,
the –u option indicates that the functions
named in the command line are not yet defined. The attributes specified
by the typeset command are applied to the
functions once they are defined.
- –x
- Sets each variable for automatic export. See export.
The last three options that follow justify, within
a field, the values assigned to each variable. The width of the field
is
number if it is defined and is nonzero;
otherwise, the width is that of the first assignment made to variable.
- –L[number]
- Left-justifies the values assigned to each variable by first removing
any leading blanks. Leading zeros are also removed if the –Z option
has been turned on. Then blanks are added on the end or the end of
the value is truncated as necessary. If the –R flag
is currently turned on, this option turns it off.
- –R[number]
- Right-justifies the values assigned to each variable by adding
leading blanks or by truncating the start of the value as necessary.
If the –L flag is currently turned on, this
option turns it off.
- –Z[number]
- Right-justifies values assigned to each variable. If the first
nonblank character of value is a digit, leading zeros are used. See
also the –L option.
Usage notes
typeset is
a built-in shell command as well as a separate utility.
An
autoloaded function is defined (loaded) by the /bin/sh shell when
invoked as a command name, it's not already defined to the shell,
and the function definition file is found in a directory specified
in the FPATH variable. (For more information
see Command execution under the sh command.)
To replace an autoloaded function, use the unset -f name command.
The next time the function name is invoked, the FPATH search
will find the new version.
Localization
typeset uses
the following localization environment variables:
- LANG
- LC_ALL
- LC_MESSAGES
- NLSPATH
See Localization for more
information.
Exit values
- 0
- Successful completion
- 2
- Failure due to an incorrect command-line argument
If the command is used to display the values of
variables, the exit status value is the number of names that are incorrect.
Messages
Possible error messages include:
- Base number not in [2,36]
- You used the –i option to specify a
base for an integer, but the base was not in the range 2 through 36.
All bases must be in this range.
- name not a function
- You tried to declare the given name as a function, but the name
already referred to something that was not a function (for example,
a variable).
Portability
POSIX.2. It
is an extension to the POSIX.2 and
XPG standards.
Related information
export, readonly, sh