Setting variables on the command line, Setting variables in your .profile file – HP NonStop G-Series User Manual
Page 47

Setting Variables on the Command Line
To set a variable on the command line, simply enter an assignment statement. For example, you
can create a variable called place by assigning it a value of U.S.A. with the following statement:
$ place='U.S.A.'
After entering this statement, you can use the variable place just as you would use its assigned
value. To denote that an assigned variable is not a literal string, type a $ (dollar sign) in front of
its name: $place. This is known as “parameter substitution.”
For example
$ echo $place
returns the following display:
U.S.A.
In another example, a variable is assigned the value of a very long, frequently used pathname.
To define the variable reports for the directory /usr/sales/shoes/women/retail/reports,
enter the following:
$ reports=/usr/sales/shoes/women/retail/reports
After assigning this variable, you can enter $reports in place of the pathname:
$ cd $reports
In this example, the shell substitutes the variable reports with the pathname
/usr/sales/shoes/women/retail/reports
. Enter the pwd command to confirm that the
current directory has changed:
$ pwd
/usr/sales/shoes/women/retail/reports
Variable assignments entered at the command line are valid only for the current session. They are
cleared when you terminate the current osh process.
Setting Variables in Your .profile File
If you wish to make the variables place and reports permanent, enter their assignment statements
and the export command in your .profile file. When you export a variable from your shell,
it becomes in effect an environment variable.
For example, in your .profile file, enter:
export place=U.S.A.
export reports=/usr/sales/shoes/women/retail/reports
When you use the variables defined in .profile, you must place a $ (dollar sign) in front of
their names to denote that they are variables, as described in
“Setting Variables on the Command
. (This is known as “parameter substitution.”)
Another way to make a permanent variable assignment is to enter it in your .profile file as an
alias.
For example, in your .profile file, enter:
alias place='U.S.A.'
alias reports=/usr/sales/shoes/women/retail/reports
For more information on aliases, see
The variables you assign in the .profile file do not become active until you either exit the current
osh
process and start a new osh process, or you reexecute .profile with either of the following
commands:
$ . .profile
or
Environment Variables
47