9

I frequently refer to man bash to recall use of "history expansion" parts(events/words/modifiers). I know that the man part I need is "HISTORY EXPANSION". So I type in HISTORY EXPANSION in forward search list '/'. Of course less jumps not straightforward to the "HISTORY EXPANSION" part, but instead shows all occurrences of this string in given man. Thus, I thought it would be great to type something like:

/^HISTORY EXPANSION 

so I could jump to "start of line"HISTORY EXPANSION.

Neither /^HISTORY EXPANSION nor /\^HISTORY EXPANSION work

In less man I see that ...

/pattern
Search forward in the file for the N-th line containing the pattern. N defaults to 1. The pattern is a regular expression, as recognized by the regular expression library supplied by your system.

I see that other men were also looking into this, but with a different purpose: https://stackoverflow.com/questions/14698364/what-is-the-regular-expression-library-supplied-by-my-system

I followed the steps, but still cannot say for sure what regex version is used on my machine. Here is the shared lib dependencies output for less binary

$ ldd /usr/bin/less linux-vdso.so.1 => (0x00007ffc229cb000) libtinfo.so.5 => /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007f44968e9000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f4496524000) /lib64/ld-linux-x86-64.so.2 (0x00007f4496b12000) 

So, how to indicate start of line in less search, so I can easily jump to the parts of man I need?

13
  • 1
    Typing /^HISTORY EX followed by return works for me in the manual of bash on a Linux system. I can't reproduce your issue. Commented Jan 22, 2018 at 11:09
  • man is not really appropriate for a manual this big. I would recommand formats with support for index and/or table of content, like info with which you have a searchable index (i, then type history expansion with tab completion) Commented Jan 22, 2018 at 11:10
  • Possibly related: Grep: unexpected results when searching for words in heading from man page Commented Jan 22, 2018 at 11:11
  • IOW, I can reproduce your issue if I run man as GROFF_SGR=1 MANPAGER='less -r' man bash. You'd want to make sure less is run with -R instead of -r (for it do understand those SGR escape sequences as opposed to pass them through), or use GROFF_NO_SGR to revert to the traditional way of doing bold/underline. Commented Jan 22, 2018 at 11:28
  • @Kusalananda set PAGER=more, and your search will fail. Commented Jan 22, 2018 at 11:29

2 Answers 2

3

Having tried and experimented it appears that man actually indents lines with spaces. This is the reason I could find
/^HISTORY EXPANSION
and failed with
/^The history library(This is the first sentence in HISTORY EXPANSION section). Here is the correct pattern:
/^[[:space:]]{7}The history library...
As we can see man/less simply adds 7 "spaces"(ascii dec code 32) in front of each line that is not a section header (in bold, as I see other people speak). I cannot say for sure whether this is true with all Linux distros/man binaries, but with all I tested so far this is true. To sum up in order to find(from first search) description of '-atime' option in man find use
/^[[:space:]]{7}-atime

1

When man's output passes through more, each bold character is in fact that character, followed by a backspace, followed by repeating that character and then to the next character. To find something in bold, search for /^H..I..S..T

You'll find it also in the article Stéphane pointed to.

1
  • 1
    But less understands those and its search facility will work on the rendered text. It's different though when roff uses SGR escape sequences for bold/underline and less is called with -r. Commented Jan 22, 2018 at 11:31

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.