As discussed earlier in this chapter, two or more commands may
have the same
Reserved word
Alias
Special built-in
Function
Regular built-in
Executable file
You can override this search order to a point because of the following rules:
The command utility ignores aliases and functions.
The builtin utility will only run a built-in.
An initial backslash ignores aliases and functions.
For example, in Figure 12.20, an
echo
function has been
created. It displays all arguments,
|
|
function echo ()
>
{
>
print "==>
$
@"
>
}
/home/jsmith $
type -a echo
echo is a shell built-in.
echo is a function.
echo is /usr/bin/echo.
/home/jsmith $
echo
$
QSH_VERSION
==> V5R2M0
/home/jsmith $
builtin echo
$
QSH_VERSION
V5R2M0
|
|
In Figure 12.21, an alias is created with the same name as the ls utility, which is an executable file in the /usr/bin directory. The alias takes precedence over the file unless the alias is preceded by a backslash.
|
|
ls *.txt edity.txt goodoleboys.txt temp.txt test1a.txt ftpmodel.txt myfile.txt test1.txt /home/jsmith $ alias ls=ls -l /home/jsmith $ type -a ls ls is an alias for ls -l. ls is /usr/bin/ls. /home/jsmith $ ls *.txt -rwx---rwx 1 JSMITH 0 800 Oct 19 15:59 edity.txt -rwxrwxrwx 1 JSMITH 0 43 Feb 22 2002 ftpmodel.txt -rwxrwxrwx 1 JSMITH 0 746 Oct 22 22:18 goodoleboys.txt -rwxrwxrwx 1 JSMITH JSMITHGP 0 Oct 24 18:03 myfile.txt -rw-rw-rw- 1 JSMITH JSMITHGP 51 Oct 23 17:34 temp.txt -rw-rw-rw- 2 JSMITH 0 7 Feb 4 2002 test1.txt -rw-rw-rw- 2 JSMITH 0 7 Feb 4 2002 test1a.txt /home/jsmith $ \ls *.txt edity.txt goodoleboys.txt temp.txt test1a.txt ftpmodel.txt myfile.txt test1.txt
|
|
When you run an application or script, Qshell does not search
all directories in the IFS. It searches only the directories listed
in the PATH variable. If Qshell does not find an executable file of
the proper name, it
The PATH variable contains a list of directories that are to be searched for external files. The directories must be separated by colons. The default value for PATH is /usr/bin: . If you want Qshell to search the current directory, you must include the current directory in the path name.
There are four ways to
An initial
Two adjacent colons within the path value
A trailing colon on the path
A period in the path variable
The following example uses the print utility to display the current path:
print $PATH /usr/bin:/home/jsmith/bin:
In this example, there are two directories in the path. Because the path name ends with a colon, Qshell will also search the current directory after searching the directories in the path.
To define the path, assign a value to the PATH variable:
PATH=/:/home/jsmith:/usr/bin:/home/jsmith/bin
To add more directories to a path, include the $PATH expansion in an assignment to the PATH variable. Surround the assigned value with double quotes, not single quotes, so that Qshell can substitute the current path into the assignment:
print $PATH /usr/bin:/home/jsmith/bin: /home/jsmith $ PATH="$PATH/QOpenSys/usr/bin" /home/jsmith $ print $PATH /usr/bin:/home/jsmith/bin:/QOpenSys/usr/bin
The hash utility, shown in Figure 12.22, maintains a list of the locations of utilities. When a utility is executed for the first time in a Qshell session, hash searches for the utility and stores its location in a list. When the utility is later executed in the same process, Qshell does not have to look through directories for the utility, but retrieves the utility from the location named in the list.
|
|
{% if main.adsdop %}{% include 'adsenceinline.tpl' %}{% endif %}
hash ls=/usr/bin/ls donde.qsh=/home/jsmith/bin/donde.qsh mv=/usr/bin/mv function echo
|
|
You may use the -r option of hash to clear the list of utility locations, as shown in Figure 12.23.
|
|
hash rm=/usr/bin/rm ls=/usr/bin/ls /home/jsmith $ hash -r /home/jsmith $ hash /home/jsmith $
|
|
With V5R2, IBM added the
p
option to the
hash
utility, which allows you to store a
hash -p filename utility
For example, in the following command, Qshell is to look for the donde.qsh script in directory /home/jsmith:
hash -p /home/jsmith/donde.qsh donde.qsh
In the following example, whenever Qshell is told to run the wer command, it will run script donde.qsh in directory /home/jsmith:
hash -p /home/jsmith/donde.qsh wer