11

In man parallel_tutorial (for GNU parallel) I’ve found the following black magic:

LESS=+/EXAMPLE\: man parallel

Searching around in the man pages for man, less, and bash, it appears this may have something to do with a less preprocessor, but I’m not sure, and the first few attempts I made to search other manual pages with this syntax failed.

What does +/...\: mean in bash?

3
  • Your highlight section does not have \: The back-slash is missing. Did you mean to?
    – mike65535
    Commented May 12, 2018 at 11:04
  • @mike65535 , it is typed in, if you hit 'edit', you can see it. It doesn't get displayed though.
    – Aganju
    Commented May 12, 2018 at 12:45
  • Escaping the \ with another backslash should work. To short for me to edit though.
    – Orphevs
    Commented May 12, 2018 at 13:27

2 Answers 2

11

It doesn't mean anything in bash. It's some arbitrary text that gets stored in the $LESS environment variable for that single command.

But when you run less, it reads the contents of $LESS and interprets them much like command-line arguments. Usually this is where you'd store configuration for it.

(less is not a preprocessor: it's a simple text file viewer, aka a pager. Note that man has no built-in reader: it just generates the text via groff (the actual preprocessor), then always runs either less or some other pager to scroll through it. The authors of that tutorial assume your system will be using less because it's so ubiquitous.)

When less encounters arguments starting with a +, the remainder is further interpreted as commands or keypresses to simulate: e.g. if it were +G then less would pretend you had pressed G after opening the file, and would scroll down.

In your case, less pretends you had typed /EXAMPLE: after opening the file. / is the search key/command in less, and the rest is the text to search for.

The result is that the command opens the manpage of "parallel", then scrolls down to the section titled "EXAMPLE".

4
  • 1
    Which the tutorial's author apparently found too difficult to express in ordinary English. Commented May 12, 2018 at 10:27
  • Well, it's is GNU... :P Excellent answer btw, popped up just as I began writing so good timing too!
    – bertieb
    Commented May 12, 2018 at 10:45
  • 1
    Strictly speaking, the back-slash before the colon is relevant to bash, as it stops the colon from having a special meaning, which it doesn't have in bash, though it may in another shell.
    – AFH
    Commented May 12, 2018 at 10:46
  • 1
    @grawity The context in the tutorial is: "Then look at the EXAMPLEs after the list of OPTIONS in man parallel (Use LESS=+/EXAMPLE\: man parallel)". How would you have expressed it in ordinary English?
    – Ole Tange
    Commented May 12, 2018 at 23:29
7

As grawity's excellent answer indicates, it's a way of giving an instruction to the less pager. In this specific case, using the manual and tutorial of GNU Parallel, it makes reading the examples easy.

As you can see from even the table of contents in the online manual, each example starts with the string EXAMPLE:, so the command LESS=+/EXAMPLE: man parallel lets you jump to the fist example, and subsequent examples by pressing n (for next match).

For example:

screencap of jumping through manual

(each jump in manual section is a n keypress)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .