1

/bin/less is the default pager on an Ubuntu 14.04.3 LTS desktop OS (the $PAGER variable is unset) and gnome-terminal 3.6.2-ubuntu1 is used.

If I try for instance:

$ man man

The displayed output conforms to the width of the current Gnome terminal window. No problem there. However when I do:

$ man man | egrep regex

The output does not automatically recognize the terminal window's width. With a setting of 83 columns in terminal's menu Edit > Profile Preferences > Default size, some lines do not conform to the terminal width and are not correctly adjusted to width. As a result I get several instances of:

<standard input>:981: warning [p 8, 0.5i, div `3tbd1,0', 0.0i]: cannot adjust line

(some characters in the warning above vary from warning to warning, presumably because they point to problematic output lines located at different place in the output.)

The pager does not seem to be at fault since this doesn't happen with the command man man.

Could it be the pipe or the rhs of the pipe disrupting things from the point of view of conforming to the Gnome terminal window width ? Is there a way to remedy that ?

EDIT 1: Is there a way to remedy that at session level, i.e. automatically, i.e. without having to check for Gnome terminal's current window width everytime I type a cmd-line that will print to stdout ?

6
  • Are you asking about bash, or about man? Your title says bash, but then your description of what goes wrong is the output of man, which bash has nothing to do with. Aug 7, 2015 at 22:08
  • @Gilles: sorry, just saw yr comment. man ... is just an example. Definitely ! I am definitely asking about the bash implementation of either the pager or what the pager does when the output is processed through a pipe or something else that garbles the correct output width adjustment in Gnome terminal. I am stumped because I don't know where to start to find the beginning of an answer. Pliz see my comment below Steve's answer. Cheers.
    – Cbhihe
    Aug 9, 2015 at 21:21
  • I still don't understand what you're asking. Do you want man man | egrep regex to be formatted to 83 columns if the terminal is 83 columns wide? Note that bash has nothing to do with the pager — the pager is less unless you've configured a different one, but the program that formats the content to a certain number of columns is man. If you thought that egrep or bash was doing the formatting, well, it's man, and its output is a pipe, not the terminal. Aug 9, 2015 at 21:35
  • @Gilles: As per my OP less is the pager on that particular box. In my example man output to pipe is just to exhibit what I find to be the bizarre behavior I get as far as the paging goes. Even so I thought that piping the output could correspond to a particular implementation of pipe by bash. If I'm mistaken, so be it; it is not important per se. *** How do I make any output conform to any terminal window width I may have arbitrarily set. I.e. either before opening the particular terminal window, or after opening the window but before executing any cmd-line printing to stdout.
    – Cbhihe
    Aug 9, 2015 at 21:57
  • What operating system are you running? I get lines with the terminal width and no warning on Debian jessie. Aug 9, 2015 at 23:01

2 Answers 2

1

I use:

 echo $COLUMNS

instead of stty. Maybe it works for you too. Maybe it depends on stty.

0

In answer to your main question : yes, from within a bash shell it is possible to recognise the size of a terminal window. Command stty is one way to determine this from any shell.

$ stty -a|head -1
speed 38400 baud; rows 49; columns 90; line = 0;
$ stty size
49 90
$
3
  • bash has nothing to do with it. It's the actual terminal that's doing that.
    – Celada
    Aug 6, 2015 at 21:11
  • You're right, my wording was unclear. Now revised.
    – steve
    Aug 6, 2015 at 21:14
  • Steve and @user unknown, thank you. I must have worded my question badly, because your answers were completely beside my intended query. I want to do this automatically from the command line. I do not want to have to embed every cmd-line that I type in a script that determines the present Gnome terminal column-width then pass this on to the pager before the cmd-line prints out to stdout. That would be completely unpractical and pretty cumbersome at best. Maybe another way to put the last question is: is what happening (as per my OP's description) fixable at session level ?
    – Cbhihe
    Aug 7, 2015 at 8:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.