DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Automating frequent tasks

Solving problems with the environment

A particularly common error is to fail to include ``.'' (the current working directory) in your PATH variable. (Note that PATH recognizes a colon with no trailing characters, or a colon followed immediately by another colon and a pathname, as synonyms for ``.''.) When the shell reads a command name it only searches for an executable file of that name in the directories listed in PATH. If ``.'' is not included in PATH, the shell will not look for the file in your current directory. Including ``.'' in PATH removes the necessity of ever having to use the ``./'' notation to execute your scripts (see ``Creating a shell script'').

Another common error is to give your file the same name as an existing command. If the current directory (.) precedes the directory in which the synonymous command exists in your PATH, your script will be used instead of the command whenever you call it; on the other hand, if the directory in which the command exists is before ``.'' in your PATH, the command will be executed instead of your script.

Consider the following search path:

/bin:/usr/bin:/u/charles/bin::/usr/sco/bin:/u/bin:

For example, if you create a script called test in the current directory, and you attempt to execute it by typing the command test, the shell will search along your path and execute /bin/test instead of ./test (pointed to by the fourth, null, field in the path).

Try to avoid giving your scripts a name already used by a SCO OpenServer utility. A quick way to test a proposed name is to invoke man on it; if man provides a manual reference, it is a bad idea to use the name. It is also worth checking the relevant manual page for the shell you are using, in case your script shares a name with a built in shell command.

Another common problem is to invoke a script under the wrong shell. To ensure that the script is always run by the correct shell, use the hash-bang notation (#!) on the first line of the script to specify which shell to use (See
``Running a script under any shell'').


Next topic: Solving problems with your script
Previous topic: What to do if something goes wrong

© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003