Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I find out the number of maximum rows and character columns in an open bash terminal window?

I know I can find out using the curses C library like this:

getmaxyx(stdscr, mrow, mcol);

I would like to associate the mrow and mrol bash variables to my bash session in the same way.

share|improve this question
up vote 3 down vote accepted

Bash already has the variables you are looking for built in: $LINES and $COLUMNS.

Unfortunately these only work in interactive shells and not generally for scripts, but it is possible to set the script to be interactive by adding a switch to the script's shebang line:

#!/bin/bash -i

share|improve this answer

Xterm comes with a tool called resize, which can be used inside scripts to set the same variables:

eval $(resize)
echo "The screen is $COLUMNS columns wide."
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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