then looks for a lesskey file called "_lesskey" in any directory specified in the PATH environment variable. On OS/2 systems, less looks for a lesskey file called "$HOME/lesskey.ini", and if it is not found, then
looks for a lesskey file called "lesskey.ini" in any directory specified in the INIT environment variable, and if it not found there, then looks for a lesskey file called "lesskey.ini" in any directory specified in
the PATH environment variable. See the lesskey manual page for more details.
A system‐wide lesskey source file may also be set up to provide key bindings. If a key is defined in both a local lesskey file and in the system‐wide file, key bindings in the local file take precedence over those in
the system‐wide file. If the environment variable LESSKEYIN_SYSTEM is set, less uses that as the name of the system‐wide lesskey file. Otherwise, less looks in a standard place for the system‐wide lesskey file: On
Unix systems, the system‐wide lesskey file is /usr/local/etc/syslesskey. (However, if less was built with a different sysconf directory than /usr/local/etc, that directory is where the sysless file is found.) On MS‐
DOS and Windows systems, the system‐wide lesskey file is c:\_syslesskey. On OS/2 systems, the system‐wide lesskey file is c:\syslesskey.ini.
Previous versions of less (before v582) used lesskey files with a binary format, produced by the lesskey program. It is no longer necessary to use the lesskey program.
INPUT PREPROCESSOR
You may define an "input preprocessor" for less. Before less opens a file, it first gives your input preprocessor a chance to modify the way the contents of the file are displayed. An input preprocessor is simply an
executable program (or shell script), which writes the contents of the file to a different file, called the replacement file. The contents of the replacement file are then displayed in place of the contents of the
original file. However, it will appear to the user as if the original file is opened; that is, less will display the original filename as the name of the current file.
An input preprocessor receives one command line argument, the original filename, as entered by the user. It should create the replacement file, and when finished, print the name of the replacement file to its stan‐
dard output. If the input preprocessor does not output a replacement filename, less uses the original file, as normal. The input preprocessor is not called when viewing standard input. To set up an input preproces‐
sor, set the LESSOPEN environment variable to a command line which will invoke your input preprocessor. This command line should include one occurrence of the string "%s", which will be replaced by the filename when
the input preprocessor command is invoked.
When less closes a file opened in such a way, it will call another program, called the input postprocessor, which may perform any desired clean‐up action (such as deleting the replacement file created by LESSOPEN).
This program receives two command line arguments, the original filename as entered by the user, and the name of the replacement file. To set up an input postprocessor, set the LESSCLOSE environment variable to a com‐
mand line which will invoke your input postprocessor. It may include two occurrences of the string "%s"; the first is replaced with the original name of the file and the second with the name of the replacement file,
which was output by LESSOPEN.
For example, on many Unix systems, these two scripts will allow you to keep files in compressed format, but still let less view them directly:
lessopen.sh:
#! /bin/sh
case "$1" in
*.Z) TEMPFILE=$(mktemp)
uncompress -c $1 >$TEMPFILE 2>/dev/null
if [ -s $TEMPFILE ]; then
echo $TEMPFILE