Shell procedures, Writing and running shell procedures – HP NonStop G-Series User Manual
Page 51
the system administrator specifies default PATH directories for new users. However, more
experienced users may need to change these PATH directories.
The PATH variable contains a list of directories to search, each separated by a : (colon). The order
in which the directories are listed is the search order that the shell uses to search for the commands
that you enter.
To determine the current value of PATH, use the echo command. For example:
$ echo $PATH
/bin:/bin/X11
This output from the echo command (your output may vary) tells you that the search order of the
preceding example is the following:
•
The /bin directory is searched first.
•
The /bin/X11 directory is searched second.
Typically, PATH is set as an environment variable in your .profile file.
If you want to change the search path, you can assign a new value to the PATH variable. For
example, assume that you have decided to use your own versions of some OSS commands. As a
result, you wish to add $HOME/bin at the beginning of the search path. To do so, enter the
following on the command line if you wish the new PATH variable value to be in effect for the
current shell session:
$ PATH=$HOME/bin:/bin:/bin/X11
If you want this new PATH variable value to be in effect for all future sessions, modify the PATH
variable in your .profile script. When you next run osh, the changes in your .profile file
will take effect.
Shell Procedures
In addition to running commands from the command line, the shell can read and run commands
contained in a file. Such a file is called a “shell procedure” or “shell script.”
Shell procedures are easy to write, and using them can help you work more efficiently. For example,
you can place frequently used commands in one file, and then execute them by entering only the
name of the procedure. As a result, shell procedures are useful for doing repetitious tasks that
would normally require entering a number of commands on the command line.
Furthermore, because shell procedures are text files that do not have to be compiled, they are easy
to create and to maintain.
The OSS shell follows the syntax and includes many of the features of the UNIX Korn shell. Some
of the programming features of the osh shell include:
•
Storing values in variables
•
Testing for predefined conditions
•
Executing commands repeatedly
•
Passing arguments to a program
Writing and Running Shell Procedures
To write and run a shell procedure, do the following:
1.
Create a file of the commands you need to accomplish a task. Create this file as you would
any text file; that is, with vi or another editing program. The file can contain any system or
shell command (described in the sh(1) reference page either online or in the Open System
Services Shell and Utilities Reference Manual).
Shell Procedures
51