azekeil: (oooooooo!)
[personal profile] azekeil
How do you work out how many lines are on the screen when you're in a script in linux??

At the command line you can simply do 'echo $LINES', but in a script the LINES environment variable is no longer available. I can't work it out!!!

Someone help me before I go mad!

Date: 2005-05-19 12:54 pm (UTC)
From: [identity profile] thespirit3.livejournal.com
I guess this is because a script isn't guaranteed to be running in a terminal. If it's running on a console I'd probably assume the standard (although, that seems to be varying now frame buffers are all the rage). If it's in an xterm, I'm sure there's some other clever way of reporting the xterm dimensions/lines. I don't know how though.

Sorry, that's probably not much help.

Date: 2005-05-19 01:31 pm (UTC)
From: [identity profile] azekeil.livejournal.com
No, not xterm, but I agree with you that I think the reason is because you can't guarantee you're running the script from a shell. But there must still be a way to discover it if you are!!

Date: 2005-05-19 01:18 pm (UTC)
gerald_duck: (duck and computer)
From: [personal profile] gerald_duck
It's not standard for $LINES to say how many lines high the terminal is; some program is setting the environment variable for you.

Find out which program that is, and use it in your script. My guess is that the program in question is resize, which it's worth noting only gets you the information you want when you're running in an xterm or something compatible.

Alternatively, export LINES. If it's already exported, find out what's stripping your script's environment. (-8

Date: 2005-05-19 01:40 pm (UTC)
From: [identity profile] azekeil.livejournal.com
Hrm. It is for bash - the bash man page says:
       LINES  Used  by  the  select  builtin  command  to determine the column
              length for printing selection  lists.   Automatically  set  upon
              receipt of a SIGWINCH.
So I tried sending the current terminal a SIGWINCH from within the shell but it didn't make it available. Googling for LINES or $LINES or derivations is worse than useless.

I think [livejournal.com profile] thespirit3 above is correct, so I need to work out how to interrogate the properties of a tty. Any ideas?

Date: 2005-05-19 02:01 pm (UTC)
From: [identity profile] azekeil.livejournal.com
You know what? The resize command seems to give me back my variables ;)

echo `resize`
gives
COLUMNS=80; LINES=24; export COLUMNS LINES;

Date: 2005-05-19 02:21 pm (UTC)
From: [identity profile] azekeil.livejournal.com
In the end I had to do this:
LINES=`resize | grep LINES= | grep -Po '\d+'`

Date: 2005-05-20 08:05 am (UTC)
From: [identity profile] stuartl.livejournal.com
Just put `/path/to/resize` as a line in your script. The commands it outputs can be run in the shell script.

Date: 2005-05-19 01:30 pm (UTC)
From: [identity profile] serena-lesley.livejournal.com
You could count them?


*Hides*

Date: 2005-05-19 01:41 pm (UTC)
From: [identity profile] azekeil.livejournal.com
In the end that's what I did *cringe*.

The reason it needs to be done programmatically is of course that the end user can (and will want to) resize the screen to view more output. It's only a silly little program but I can't believe it's so difficult!

Date: 2005-05-20 08:41 pm (UTC)
From: [identity profile] dylan.livejournal.com
Not sure about linux but as well as the solutions above on most versions of unix you can usually use stty -a < /dev/whatever to interrogate most of the shell setup

March 2014

S M T W T F S
      1
2345678
9101112131415
16171819202122
23242526272829
3031     

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Feb. 12th, 2026 12:07 am
Powered by Dreamwidth Studios