z/OS UNIX System Services User's Guide
Previous topic | Next topic | Contents | Contact z/OS | Library | PDF


Creating a variable

z/OS UNIX System Services User's Guide
SA23-2279-00

The shell also lets you create variables. A shell variable name can consist of uppercase or lowercase letters, plus digits and the underscore character _. The name can have any length, but the first character cannot be a digit. Uppercase letters are distinguished from lowercase ones, so NAME, name, and Name are all different names.

To create a shell variable, just enter:
name='string'
as a command to the shell. No spaces are allowed around the =. For example:
HOME='/usr/macneil'
sets up a variable with the name HOME and the value /usr/macneil.
After you set a variable, you refer to it by prefixing its name with a dollar sign ($). Any command can use the value of a variable by referring to it this way. For example, if HOME is set to /usr/macneil:
cd $HOME
is equivalent to:
cd /usr/macneil
Similarly:
cp $HOME/* /newdir
is equivalent to:
cp /usr/macneil/* /newdir
To change the value of an existing variable, you use a command with the same form as the existing variable. For example:
HOME='/usr/benjk'
changes the value of HOME from /usr/macneil to /usr/benjk.
If the value on the right-hand side of the = sign does not contain spaces, tab characters, or other special characters, you can leave out the single quotation marks. For example, you can enter:
HOME=/usr/benjk

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014