| View previous topic :: View next topic |
| Author |
Message |
nixscripter n00b


Joined: 14 Jun 2008 Posts: 72 Location: Somewhere Cold, USA
|
Posted: Sat Oct 31, 2009 5:30 pm Post subject: Man pages, less, and ANSI color |
|
|
I'll say up front this is more of a suggestion than a question.
I have been driven crazy for about 3 months by something on my Gentoo server: man pages would work fine, except when I was sudoed as another user. Random escape sequences would get splattered all over the pages. It isn't a character encoding problem because
did nothing. By printing out the environment variables which differed between a sudo session and a normal session, and 15 minutes of trial and error, the culprit was:
| Code: | | LESS="-R -M --shift 5" |
What does that do? From the man page:
| Code: |
-r or --raw-control-chars
Causes "raw" control characters to be displayed.
...
-R or --RAW-CONTROL-CHARS
Like -r, but only ANSI "color" escape sequences are output in
"raw" form.
|
So apparently, without this, the ANSI color control characters are being escaped, and come out as junk (a string something like ESC[m. No wonder.
Why only sudo sessions? Because the shell variable is defined in /etc/env.d/70less (and therefore in /etc/bashrc), but is not exported. So, if someone does sudo -s, the current environment is maintained, and any non-environment variables (of course) are not propagated to the subprocess.
I find this personally annoying, but I suppose there might be a technical reason for it. Is there a particular reason why this variable isn't exported by default? And if not, might I suggest this variable be exported to avoid aggravating others? |
|
| Back to top |
|
 |
SamuliSuominen Retired Dev

Joined: 30 Sep 2005 Posts: 2133 Location: Finland
|
Posted: Sat Oct 31, 2009 5:55 pm Post subject: |
|
|
sudo -i
? |
|
| Back to top |
|
 |
nixscripter n00b


Joined: 14 Jun 2008 Posts: 72 Location: Somewhere Cold, USA
|
Posted: Sat Oct 31, 2009 11:38 pm Post subject: |
|
|
Yeah, but that changes other stuff (like home directory) and doesn't work with accounts without a home directory (e.g. apache). That's why I've gotten into the habit of -s.
I know this post is a minor quibble, but I'm just wondering if there is any good reason why one would assign a pager in bash profile (sorry, not bashrc) and then not export it. Why wouldn't you want your pager to work the same way in subshells? |
|
| Back to top |
|
 |
eccerr0r Watchman

Joined: 01 Jul 2004 Posts: 7427 Location: almost Mile High in the USA
|
Posted: Tue Nov 03, 2009 12:02 am Post subject: |
|
|
The main reason for not passing these environment variables is that it's a typical way of exploiting script and programming bugs. Sudo decides to just purge environment variables when changing to root.
While it may seem superfluous as you'll have root anyway, sudo does let you run specific commands as root and only those commands. This utilization of sudo would benefit from environment purge.
I think you can specify arbitrary variables to be exported to sudo root shells in /etc/sudoers. Something like env_delete-=LESS or something like that.
I just deal with it... _________________ Intel Core i7 2700K@ 4.1GHz/HD3000 graphics/8GB DDR3/180GB SSD
What am I supposed watching? |
|
| Back to top |
|
 |
Anon-E-moose Advocate


Joined: 23 May 2008 Posts: 4444 Location: Dallas area
|
Posted: Tue Nov 03, 2009 12:11 am Post subject: |
|
|
sudo -E _________________ PRIME x570-pro, 3700x, RX 550 & 560
Acer E5-575 (laptop), i3-7100u - i965
---both---
5.5.18 zen kernel, gcc 9.3.0, profile 17.1 (no-pie & modified) amd64-no-multilib, eudev, openrc, openbox, palemoon |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|