pathchk(1) pathchk(1)
NAME
pathchk - check pathnames
SYNOPSIS
pathchk [-p] pathname ...
DESCRIPTION
The pathchk command checks that one or more pathnames are valid (i.e.
they can be used to access or create a file without causing syntax
errors) and portable (i.e. the name need not be adjusted). More exten-
sive portability checks can be carried out with the -p option.
By default, the pathchk command checks the components of all pathname
arguments based on the underlying file system. An error message is
output for the pathname argument if:
- It is longer than the maximum permitted pathname length (PATHMAX
bytes).
- It contains a component that is longer than the maximum permitted
filename length (NAMEMAX bytes) in the relevant directory.
- It contains a component in a directory that is not searchable.
- It contains a component with characters that are invalid in the
directory.
pathchk does not consider it an error if one or more components of a
pathname argument do not exist, as long as the file with the specified
pathname can be created and does not violate any of the checks
described above.
OPTIONS
-p pathchk does not perform a check on the underlying file system,
but on generic portability conditions. An error message relating
to the pathname argument is output if:
- It is longer than the maximum permitted length for portable
pathnames (POSIXPATHMAX bytes).
- It contains a component longer than the maximum length for
portable filenames (POSIXNAMEMAX bytes).
- It contains a component with characters not contained in the
portable character set for filenames.
pathname
The pathnames to be checked.
Page 1 Reliant UNIX 5.44 Printed 11/98
pathchk(1) pathchk(1)
ENVIRONMENT VARIABLES
The following environment variables affect the execution of pathchk:
LANG Specifies the default value for the variables for the
locale that is unset or null. If LANG is unset or null,
the corresponding default value of the locale is used. If
the internationalization variable contains an invalid
setting, the command behaves as if none of the variables
were set.
LCALL If this value is set, i.e. is not empty, this value
overwrites the values of all the other variables for the
locale.
LCCTYPE Determines the interpretation of byte sequences as char-
acters (e.g. as single-byte as opposed to multibyte char-
acters in arguments).
LCMESSAGES Determines the format and content of messages.
EXIT STATUS
0 All pathnames are error-free.
>0 An error occurred.
DIAGNOSTICS
pathchk: Subpath path is not searchable
ENOSYS error reported by the pathconf() system call [see
fpathconf(2)].
APPLICATION USAGE
Using the test command you can check whether a certain pathname speci-
fies an existing file. However there is no information about whether a
component of the pathname was truncated (in a directory where the
POSIXNOTRUNC function is not activated. The pathchk command does
not check for the existence of a file. It only checks if a certain
pathname exists or if it can be created without truncating the name.
The noclobber option in the shell [compare with the description of
set(1)] can create a unique file.
Page 2 Reliant UNIX 5.44 Printed 11/98
pathchk(1) pathchk(1)
EXAMPLES
You can check if all pathnames in an imported data interchange archive
are legitimate and unambiguous on the current system as follows:
pax -f archive | sed -e '/ == .*/s///' | xargs pathchk
if [ $? -eq 0 ]
then
pax -r -f archive
else
echo Investigate problems before importing files.
exit 1
fi
You can check whether all files in the current directory hierarchy can
be transferred to another system, that the general portability condi-
tions are met, and that the pax(1) command is available as follows:
find . -print | xargs pathchk -p
if [ $? -eq 0 ]
then
pax -w -f archive .
else
echo Portable archive cannot be created.
exit 1
fi
You can check whether a specified pathname names a readable file and
whether an application can create a file by extending the filename
without truncating the pathname and without overwriting any existing
files.
case $- in
*C*) reset="";;
*) reset="set +C"
set -C;;
esac
test -r "$path" && pathchk "$path.out" &&
rm "$path.out" > "$path.out"
if [ $? -ne 0 ]; then
printf "%s: %s not found or %s.out fails \
creation checks.\n" $0 "$path" "$path"
$reset # reset the noclobber option in case a trap
# on EXIT depends on it
exit 1
fi
$reset
PROCESSING < "$path" > "$path.out"
Page 3 Reliant UNIX 5.44 Printed 11/98
pathchk(1) pathchk(1)
This example is based on the following:
1. PROCESSING displays the code used by the application in order to
use $path, once a check has been made that $path.out meets the
required conditions.
2. The state of the noclobber option is unknown if this code was
called, and should be reset on exit to the state it was in when the
code was called. (The reset variable is used to restore the initial
state in this example.)
3. Note the usage of the following construction:
rm "$path.out" > "$path.out"
a) The pathchk command has by now already checked that $path.out is
not truncated.
b) If the noclobber option is set, the shell checks that $path.out
does not already exist before rm is called.
c) If the shell has successfully created $path.out, rm removes it
again so that the application can create the file in the PRO-
CESSING step.
d) If the PROCESSING step wants the file to exist already when it
is called,
rm "$path.out" > "$path.out"
should be replaced by
> "$path.out"
This confirms that the $path.out file does not exist yet, and it
will be created for use by PROCESSING.
SEE ALSO
test(1), fpathconf(2).
Page 4 Reliant UNIX 5.44 Printed 11/98