Parameters: An Overview

When talking about zsh, a parameter is simply another term for 'variable'. Like other shells and all programming languages, a variable is simply a placeholder for a value of some type.

In this workshop, we will use the term 'parameter' and 'variable' interchangably.

In zsh, a parameter has a name, an associated value, and a number of attirbutes.

Paramter names can be any sequence of alpha-numeric characters and underscores. (There are a few special cases, namely * , @ , # , ? , - , $ , and !

Parameter values are simply the pieces of information that variables store. Values in zsh can be one of three types: strings, integers, or arrays.

Assigning Values

The easiest way to assign a value to a string or integer parameter is to type


To assign a value to an array parameter, you do something similar:

name=(value1 value2 ... valueN)

To delete any type of parameter, simply run



Shell functions delimit scope for shell parameters. This is somewhat similar to the way many programming languages such as C work.

When you read or set a variable, zsh looks in the current function to see if that variable exists. If not, it looks in the next outermost function, and so on, until it reaches the global (outermost) scope. Therefore, if you assign a value to a variable that doesn't exist, the variable gets created in the outermost scope. (Exporting a new parameter also has this effect.)

If a variable X goes out of scope, it gets deleted. (Just like in C). If there is now some variable X that exists in an outer scope, it will be used.

Positional Parameters

Positional parameters contain the arguments to the currently running shell or shell script. The parameters are named starting with the number 0, and counting up. In zsh, they can go past 9. (So $11 is the 11th argument.) $0 usually contains the name of the currently running script or shell.

There are three arrays which contain all the positional parameters: @ , * , and argv. (There are subtle differences between a couple of them - see the man page)

Position parameters can be set in three ways: upon shell invocation, by the set builtin, or by direct assignment.