Main index

Introducing UNIX and Linux


Advanced shell programming

Overview
Sending and trapping signals
      Signal names
Functions
Aliases
The 'exec' mechanism
The 'eval' mechanism
Sending data across networks
      Sending printable characters
      Splitting files
Makefiles
Safe programming
Setting up a terminal
More on files
Miscellaneous utilities
Summary
Exercises

Safe programming will give more information than test. Followed by the name of a path, pathchk will check that it does not breach any of those limits, by (for example) being simply too long. It will also check that no component of the pathname cannot be searched because it does not have execute permission. With option -p ('portable') it will also indicate any potential problems where the name may be acceptable for the current system, but breaches certain minimum limits defined by POSIX, and might thus present problems if the name were to be used on a different system.

Worked example

Is it sensible to write a script to create and use a file called instrumentation and expect this script to work on all systems?
Solution: This is a problem that concerns the portability of a filename; use pathchk with option -p:

pathchk -p instrumentation
pathchk: name 'instrumentation' has length 15; exceeds limit of 14

This message indicates that any filename of length above 14 may not be allowed on every system, so the answer is 'no'.

If, during the course of a session logged on to a UNIX system, you have reset a number of variables, it may be that you accidentally change the value of a system variable that was defined when you logged in. You can find what the values of the system-defined variables are with command getconf ('get configuration'). This can also be useful in a shell script if you wish to check that such variables have the required values. Perhaps the clearest example of where this would be useful would be in the case of PATH. It is common to reset the value of PATH, as we have already discussed, so that it includes directories within your own file space. If you were to make an error while doing this and left out one of the system directories, you might be unable to proceed as some commands you needed to use would be denied you. By using

getconf PATH

the default value would be printed out and you could reset PATH to a sensible value, which would allow you to continue.

There are a number of variables which are not 'environment' variables (and cannot be changed) but indicate the system limits (such as the maximum length of a filename allowed, and the maximum number of processes you can have running at any one time). These values can only be accessed using getconf.


Copyright © 2002 Mike Joy, Stephen Jarvis and Michael Luck