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.
To assign a value to an array parameter, you do something similar:
name=(value1 value2 ... valueN)
To delete any type of parameter, simply run
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
exists in an outer scope, it will be used.
$11is the 11th argument.)
$0usually contains the name of the currently running script or shell.
There are three arrays which contain all the positional parameters:
* , and
(There are subtle differences between a couple of them - see the man page)
Position parameters can be set in three ways: upon shell invocation,
set builtin, or by direct assignment.