1

I'm trying to read a filtered version of some files in less by using the LESSOPEN environment variable, but no matter how simple my preprocessor, the command hangs until I send it a SIGINT via Ctrl+C:

LESSOPEN='||cat' less foo bar

What am I doing wrong here? (Note that I can't just pass the input as a pipe, since I'm opening multiple files in separate buffers.)

  • Right now, I'm wondering if this might be a bug in Less, vis. current beta release notes like greenwoodsoftware.com/less/news.520.html listing the change "Fix buffering bug when using stdin with a LESSOPEN pipe." – Stuart P. Bentley Nov 21 '17 at 3:40
  • Well, building the latest beta didn't fix the issue, so if this is a bug, it isn't that bug. – Stuart P. Bentley Nov 21 '17 at 4:05
1

You forgot the %s, without which cat didn't get a filename and is simply waiting for input from stdin:

LESSOPEN='||cat %s' less foo bar # works
LESSOPEN='||cat' less foo bar # hangs

The manpage says:

To set up an input preprocessor, 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.

  • @StuartP.Bentley nope, the command accepts both stdin and files. "the input pipe is used on standard input as well as other files." The phrase "input pipe" is misleading: what gets piped here is the output of the command in LESSOPEN to less (hence the pipe from LESSOPEN is the input to less). It doesn't mean that input files are piped to LESSOPEN in all cases. – muru Nov 21 '17 at 4:17
  • Yeah, I deleted my initial comment a few seconds after I wrote it; as you said, the phrase is misleading (STDIN is only piped to the preprocessor, with a filename of -, when the input to less itself comes from STDIN, and even then, only when LESSOPEN has a hyphen at the beginning). – Stuart P. Bentley Nov 21 '17 at 4:21
  • 1
    The good news is that the latest beta of Less includes an error message when an input pipe LESSOPEN is missing %s, so that might serve to tip others off to avoid this mistake in the future. – Stuart P. Bentley Nov 21 '17 at 4:23
  • I've sent an email to bug-less@gnu.org pointing out the omission of this detail from the man page documentation. – Stuart P. Bentley Nov 21 '17 at 4:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.