home ~ projects ~ socials

Get The Number Of Columns And Rows In A Terminal Window With ENV Vars

ENV Vars

Both bash and zsh set environmental vars for the number of columns and lines/rows in a terminal window. For example:

echo $COLUMNS

-- results

56
echo $ROWS

-- results

38

Notes

  • Not all shells set these ENV vars. Determining that is left as an exercise for the reader
  • There's also al tputs command is that can provide the info (link below)
-- end of line --

References

Use tputs To Get The Number Of Columns And Lines/Rows Count In A Terminal Window On A Mac