Man is calling Less; the only control at the man level is choosing which options to call Less with.
Less's search case-sensitivity is controlled by two options.
- If
-I
is in effect, then searches are case-insensitive: either a
or A
can be used to match both a
and A
.
- If
-i
is in effect but not -I
, then searches are case-insensitive, but only if the pattern contains no uppercase letter.
If you make -I
a default option for Less, then all searches will be case-insensitive even in man pages.
Man-db passes extra options to the pager via the LESS
environment variable, which Less interprets in the same way as command line options. The setting is hard-coded at compile time and starts with -i
. (The value is "-ix8RmPm%s$PM%s$"
as of Man-db 2.6.2; the P…$
part is the prompt string.)
If you don't want searches in man pages to be case-sensitive, or if you want them to be always case-insensitive, there is no way to configure this in man-db itself. You can make an alias for man
or a wrapper script that manipulates the LESS
enviroment variable, as Man-db prepends its content to the current value if present:
alias man='LESS="$LESS -I" man'
To turn off the -i
option and thus make searches always case-sensitive by default in man pages:
alias man='LESS="$LESS -+i" man'
You can also hard-code a different value for LESS
by setting the MANLESS
environment variable, but if you do that, then man
just sets LESS
to the value of MANLESS
, you lose the custom title line (“Manual page foo(42)
”) and other goodies (in particular, make sure to include -R
for bold and underline formatting).
If you're using Bash 4 or later, you can use coprocesses:
function f () { a=3; b=4 ; echo "`date`: $a $b"; }
coproc cat
f >&${COPROC[1]}
exec {COPROC[1]}>&-
read c <&${COPROC[0]}
echo a $a
echo b $b
echo c $c
will output
a 3
b 4
c Sun Jun 29 10:08:15 NZST 2014: 3 4
coproc
creates a new process running a given command (here, cat
). It saves the PID into COPROC_PID
and standard output/input file descriptors into an array COPROC
(just like pipe(2)
, or see here or here).
Here we run the function with standard output pointed at our coprocess running cat
, and then read
from it. Since cat
just spits its input back out, we get the output of the function into our variable. exec {COPROC[1]}>&-
just closes the file descriptor so that cat
doesn't keep waiting forever.
Note that read
takes only one line at a time. You can use mapfile
to get an array of lines, or just use the file descriptor however you want to use it in a different way.
exec {COPROC[1]}>&-
works in current versions of Bash, but earlier 4-series versions require you to save the file descriptor into a simple variable first: fd=${COPROC[1]}; exec {fd}>&-
. If your variable is unset it will close standard output.
If you're using a 3-series version of Bash, you can get the same effect with mkfifo
, but it's not much better than using an actual file at that point.
Best Answer
LESS
has no special meaning toman
, butless
pager, whichman
uses by default on most systems.On my Debian, if no pager was specified,
man
will usepager -s
by default.LESS
specifies which options will be passed toless
. The+cmd
tellless
to executecmd
upon open. Here+/'^ *shopt \['
tellsless
to search for line match regex^ *shopt \[
, which you can do manually by runningman bash
, then pressing/
and typing the regex.If you change the pager,
LESS
has no effect: