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


Creating a shell 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:
set name='string'
as a command to the shell. For example:
set home='/usr/adams'
sets up a variable with the name home and the value /usr/adams.
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/adams:
cd $home
is equivalent to:
cd /usr/adams
Similarly:
cp $home/* /newdir
is equivalent to:
cp /usr/adams/* /newdir
To change the value of an existing variable, you use a command with the same form as the existing variable. For example:
set home='/usr/benjk'
changes the value of home from /usr/adams 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