declare, local, typeset

assign attributes and values to KornShell variables 

KornShell Built-in


SYNOPSIS

declare -f|-F {-p] {±tux] [name[=value] ...]

declare {-p] [±HhIlPrtux] [±iLRZ[number]] [name[=value] ...]

local {±HhIlPrtuxx] [name[=value] ...]

typeset -f|-F {-p] {±tux] [name[=value] ...]

typeset {-p] [±HhIlPrtux] [±iLRZ[number]] [name[=value] ...]


DESCRIPTION

Invoking typeset with no options displays a list of all KornShell variables showing their names, values, and attributes. This list is sorted by variable name and includes quoting so that it can be re-input to the KornShell with the built-in command eval. When only arguments of the form +option are specified, typeset displays a list of the variables which 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.

If the command line contains at least one name, the attributes of each specified name 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. Parameters of the form name=value turn on the associated attributes and also assign value to name.

When typeset is invoked inside a function, a new instance of each name is created. After the function terminates, each name is restored to the value and attributes it had before the function was called.

The declare utility behaves similarly to the typeset utility except that when no options or arguments are specified, declare lists all shell variables with their values (but not their attributes) as well as all functions with their definitions (but again not their attributes).

The local utility can only be used within a function and specifies that variable name is local to that particular function and its children. An error occurs if you use local outside a function. When no options or arguments are specified, local does nothing and returns.

Options

-F 

does not display function definitions. Only function names and attributes are displayed. This option implies -f.

-f 

treats all specified names as functions not variables. The built-in alias functions is equivalent to typeset -f. The built-in alias autoload is equivalent to typeset -fu.

If you specify only the -f or -F option but no arguments, typeset and declare list all defined functions in the environment. (with definitions for typeset but without definitions for declare). You can combine this with the -u option to list all undefined functions.

-H 

performs POSIX to host-name file mapping. For example, on Windows systems, slashes are mapped to backslashes. If the -h option is currently turned on, this option turns it off.

-h 

performs host-name to POSIX file mapping. For example, on Windows systems, slashes are mapped to backslashes. If the -H option is currently turned on, this option turns it off.

-i[number

marks each variable as an integer value, making arithmetic faster. If number is given and non-zero, the output base of each name is number.

The -L, -R, and -Z options do not work with integer variables.

-I 

handles names in a case-insensitive manner. With this option, Var , var, and VAR all refer to the same variable. If two or more variables exist which, when the command is issued, have the same name as name, typeset issues an error message.

-l 

converts uppercase characters to lowercase in any value assigned to a name. If the -u option is currently turned on, this option turns it off.

-P 

marks the variables as having a value which is interpreted as a path name or a list of path names separated by colons or semicolons. While their values are always stored internally in Windows format, such variables can have their values displayed in either Windows or UNIX format. The output format depends upon whether or not the variable has the -H property set, whether or not the Enhanced UNIX Compatibility Mode is on, and the setting of the TK_PATH_CONVERT environment variable.

When the -H property is set, the output format is Windows format. When -H is not set and the Enhanced UNIX Compatibility Mode is on, the output format is UNIX format with virtual file system path names. When the -H property is not set and the Enhanced UNIX Compatibility Mode is off, the output format uses Windows path names with /x=/ used in place of x:/ to specify drive letters and : used as the directory separator. In all other situations, the output is in Windows format.

See the Environment Variables and Paths section of the EUCM reference page for more information.

-p 

causes the output generated by typeset or declare to be in a form that is suitable for use as input to the shell for setting variables.

If you specify the -p option with no other options or arguments, the result is similar to specifying no options or arguments whatever, except that the output is in a form suitable for use as input to the shell.

Similarly, if you specify the -p option with only the -f or -F option but no arguments, only defined functions are listed (with definitions for typeset but without definitions for declare). Again, this is in a form suitable for use as input. You can list all undefined functions by adding the -u option.

-r 

makes each name read-only. See readonly.

-t 

tags each name. 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 name. If the -l option is currently turned on, this option turns it off.

When used with -f, -u 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. See the functions reference page for a full description of undefined functions and the autoload alias.

-x 

sets each name for automatic export. See export.

The following three options justify, within a field, the values assigned to each name. The width of the field is number if it is defined and non-zero; otherwise, the width is that of the first assignment made to name.

-L[number

left justifies the values assigned to each name by first removing any leading blanks. Leading zeroes are also removed if the -Z option has been turned on. Blanks are added on the end or the end of the value is truncated as necessary. If the -R option is currently turned on, this option turns it off.

-R[number

right justifies the values assigned to each name by adding leading blanks or by truncating the start of the value as necessary. If the -L option is currently turned on, this option turns it off.

-Z[number

right justifies values assigned to each name. If the first non-blank character of value is a digit, leading zeroes are used. See also the -L option.

Note:

The -L, -R, and -Z options do not work with integer variables.


ENVIRONMENT VARIABLES

FPATH 

contains a semicolon-separated list of directories to search for function definitions when an undefined function is executed.

Additionally, if this variable is defined and a PATH search fails to locate a command named cmdname, the directories specified in this variable are searched directory by directory for a script named cmdname.ksh or if that is not found, a script named cmdname. If such a script is found, it is executed in the current shell environment. Once that script has executed, the function cmdname, whose definition should have been included in the executed script, is now executed. If the function cmdname is still undefined, an error results.

For a full description of undefined functions and the autoload alias, see the functions reference page.

TK_PATH_CONVERT 

Determines whether or environment variables that are considered to contain path names are displayed in Windows or UNIX format. When this variable is set to UNIX (this value is case-insensitive), such an enivronment variable is displayed in UNIX format; otherwise, it is displayed in Windows format. See the Environment Variables and Paths section of the EUCM reference page for more information.

TK_UNIX_FILESYSTEM 

When this variable is set, the Enhanced UNIX Compatibility Mode is on and the virtual file system is in use. For more information, see the EUCM reference page.


DIAGNOSTICS

Possible exit status values are:

0 

Successful completion.

>0 

An error occurred. The return value may be the number of invalid names specified on the command line.

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 

The given name is not defined as a function.


PORTABILITY

Windows 8.1. Windows Server 2012 R2. Windows 10. Windows Server 2016. Windows Server 2019. Windows 11. Windows Server 2022.


NOTE

The declare, local, and typeset commands are built into the MKS KornShell.


AVAILABILITY

PTC MKS Toolkit for Power Users
PTC MKS Toolkit for System Administrators
PTC MKS Toolkit for Developers
PTC MKS Toolkit for Interoperability
PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition
PTC Windchill Requirements and Validation


SEE ALSO

Commands:
export, functions, integer, readonly, sh

Miscellaneous:
EUCM


PTC MKS Toolkit 10.4 Documentation Build 39.