0

In man argument/flag/option chapters generally include a line break, as with:

-s
    silent

How could I find only the -s which includes a line break after it, just as in the above example?

The purpose is to prevent a case where I find an -s inside a text block (i.e. without a line break after it).

3
  • I don't quite understand: If the option is -s, and it has no parameter, you would search for "-s" only. If -s has a parameter it would be on the same line usually. Maybe explain what you try to do actually.
    – U. Windl
    Mar 17, 2022 at 10:20
  • @U.Windl I have explained what I tried to do, to search for -s before a line break but in man for curl I found it in another way, in the end of a block of text and without any such line break. Why? I don't know, the relevant author of man for curl knows.
    – Lahor
    Mar 17, 2022 at 23:32
  • I checked for curl-7.66.0 ("16 Dec 2016"): There I see "-s, --silent" on a single line. That manual page was created with "curl project gen.pl man page generator".
    – U. Windl
    Mar 18, 2022 at 8:02

1 Answer 1

2

It depends what pager you use.

If using the less pager, search strings (as when you type / or ?) are actually extended regular expressions (with less-specific extensions).

As a regular expression, -s$ would match on a -s (or -S as searches ignore case by default in less when called by man unless the search pattern contains an uppercase letter, type -i for case sensitive) that is at the end of the line. -s[[:space:]]*$ would match on -s, followed by 0 or more spacing characters followed by the end of the line.

With the most pager, searches are just plain string that are found in the contents of lines, so you're left without an option there.

You can specify which pager man will use to display the formatted man page with the $PAGER environment variable. With the implementation from man-db, you can also specify it with the -P option which takes precedence over the $MANPAGER environment variable which itself takes precedence over the $PAGER variable.

Which pager is used by default depends on the system and man implementation. On my system (Debian), man (from man-db) invokes the pager command (which is managed as a dpkg alternative and by default is less), but has some less-specific configurations (it sets a number of LESS* environment variables).

You could also do man some-topic | less to pipe the formatted output to less by yourself, or: man some-topic | less '+/-s$' for less to start searching for that pattern upon start, but beware that with the man-db implementation of man, redirecting the output disables the formatting.

Instead you can give less its list of options with the $LESS environment variable, but note that $ has a special meaning there, and would need to be escaped:

LESS='--use-backslash +/-s\$' man -P less some-topic
8
  • I don't know which pager man uses in my WSL-Ubuntu 18.04 system (?) If I make a search in man with -s$ I get: "Pattern not found".
    – Lahor
    Mar 13, 2022 at 17:05
  • I think it's because the man doesn't have that, rather it has entries starting as -x, I don't recall commas added in a few other manuals I've read.
    – Lahor
    Mar 13, 2022 at 17:08
  • @Lahor, that sounds like an error less would return. Does pressing V mention less <some-version> at the bottom. Here it's possible there are whitespace characters after the -s. So searching for -s[[:space:]]*$ (-s\s*$ might also work) may given you more results. Mar 13, 2022 at 17:09
  • Yes, pressing V gave less 487. I got Pattern not found, after searching -s[[:space:]]*$`. echo $PAGER output was an empty line.
    – Lahor
    Mar 13, 2022 at 17:13
  • @Lahor, that would suggest there is no line matching that pattern in your man page. Are you sure there is? Mar 13, 2022 at 17:18

You must log in to answer this question.

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