0

Many non alpha-numeric characters appear as jumbled mess when using less and man. Currently, I'm using zsh but the same problem happens in bash and sh. The problem also appears in both the st and termite terminal emulators.

man grep produces:

Broken man page

How can i fix this?

env -i TERM=$TERM PATH=/usr/bin:/bin HOME=/none man grep renders correctly.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
jeohd
  • 103
  • 2
  • 2
    it is not a jumbled mess ... those are VT100 commands that tell the terminal window how to format the displayed text ... your terminal program does not understand the commands – jsotola Nov 11 '20 at 00:20
  • I get the same issue in `xterm` as well. – jeohd Nov 11 '20 at 00:31
  • If `less -R` works, add `export LESS=-R` to your `~/.bashrc`. Read `man less`. – waltinator Nov 11 '20 at 00:48
  • it may be a messed up prompt doing this (PS1) ... does the same thing happen if you log in as root? – jsotola Nov 11 '20 at 01:54
  • 1
    @waltinator, the `man-db` implementation of `man` should already set `$LESS` to something like `-ix8RmPm`. Also, these days, those escape sequences tend not to be used by default (you'd need to set the `GROFF_SGR` env var), so there's something unusual in the OP's environment. See also [Grep: unexpected results when searching for words in heading from man page](//unix.stackexchange.com/a/371067) – Stéphane Chazelas Nov 11 '20 at 07:52
  • What distribution are you running? Have you made any configuration that you think might affect how `man` or `less` works? Does `env -i TERM=$TERM PATH=/usr/bin:/bin HOME=/none man grep` show the man page correctly, with or without formatting, in less or something else? – Gilles 'SO- stop being evil' Nov 11 '20 at 09:04
  • @Gilles'SO-stopbeingevil' Yes, `env -i TERM=$TERM PATH=/usr/bin:/bin HOME=/none man grep` renders correctly. See answer. – jeohd Nov 12 '20 at 03:48

2 Answers2

1

Since the problem disappears with a minimal environment, it's caused by an environment variable. It turns out to be your LESS_TERMCAP settings. You've set them to sequences beginning with [. They're missing the initial escape character.

csi=$(printf '\033[')
export LESS_TERMCAP_mb="${csi}1;31m"
…
Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
0

These vars were exported in my ~/.profile. Removing them solved the issue.

export LESS=-R
export LESS_TERMCAP_mb="$(printf '%b' '[1;31m')"
export LESS_TERMCAP_md="$(printf '%b' '[1;36m')"
export LESS_TERMCAP_me="$(printf '%b' '[0m')"
export LESS_TERMCAP_so="$(printf '%b' '[01;44;33m')"
export LESS_TERMCAP_se="$(printf '%b' '[0m')"
export LESS_TERMCAP_us="$(printf '%b' '[1;32m')"
export LESS_TERMCAP_ue="$(printf '%b' '[0m')"
jeohd
  • 103
  • 2