LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   problem regarding tput cols (https://www.linuxquestions.org/questions/linux-general-1/problem-regarding-tput-cols-726437/)

davender84 05-16-2009 12:22 PM

problem regarding tput cols
 
there is a command "#tput cols"
when i run this command in cli mode or linux terminal it gives result as 80
but i know that "#tput cols" is same as "#tput -Tlinux cols" because in "#tput cols" the value of terminal type is picked up from envoirement variable "TERM" (#echo $TERM) so both the above command should give the same result
but they give different resuls
#tput cols
80
#tput -Tlinux cols
-1
i think the later one is correct because there is no capability named "cols" is defined for linux terminal in terminfo database(#infocmp)
so "tput cols" should give the same result as -1 as "tput -tlinux cols"
does
pls help me why this command #tput cols runs prperly in linux terminal

colucix 05-16-2009 12:35 PM

Code:

-Ttype indicates  the  type  of  terminal.  Normally this option is unnecessary, because the
      default is taken from the environment variable TERM.  If -T  is  specified,  then  the
      shell variables LINES and COLUMNS will be ignored and the operating system will not be
      queried for the actual screen size.

I don't know why, but it is quite clear. If you want columns or rows, don't use -Ttype! ;)

davender84 05-16-2009 12:44 PM

hi
 
Quote:

Originally Posted by colucix (Post 3542961)
Code:

-Ttype indicates  the  type  of  terminal.  Normally this option is unnecessary, because the
      default is taken from the environment variable TERM.  If -T  is  specified,  then  the
      shell variables LINES and COLUMNS will be ignored and the operating system will not be
      queried for the actual screen size.

I don't know why, but it is quite clear. If you want columns or rows, don't use -Ttype! ;)

i simply know that tput cols should not run in cli mode because this capability is not supported by linux terminal so why this commands run and give proper result as 80

colucix 05-16-2009 12:52 PM

Why not? There is no mention of that in the termutils manual. tput cols can be used even in a script like this:
Code:

#!/bin/bash
COLUMNS=`tput cols` export COLUMNS # Get screen width.
echo "$@" | awk '
{ spaces = ('$COLUMNS' - length) / 2
  while (spaces-- > 0) printf (" ")
  print
}'

(from the cited manual). This prints a string at the center of the terminal.

davender84 05-16-2009 01:00 PM

hi
 
Quote:

Originally Posted by colucix (Post 3542978)
Why not? There is no mention of that in the termutils manual. tput cols can be used even in a script like this:
Code:

#!/bin/bash
COLUMNS=`tput cols` export COLUMNS # Get screen width.
echo "$@" | awk '
{ spaces = ('$COLUMNS' - length) / 2
  while (spaces-- > 0) printf (" ")
  print
}'

(from the cited manual). This prints a string at the center of the terminal.

when u use a particular terminal like linux or xterm all capabilities that these terminals have should be defined in terminfo database otherwise it will not run

davender84 05-16-2009 01:06 PM

hi
 
Quote:

Originally Posted by davender84 (Post 3542986)
when u use a particular terminal like linux or xterm all capabilities that these terminals have should be defined in terminfo database otherwise it will not run

i know that tput cols command runs in cli mode and gives the right result
but it should not run in cli mode because there is no capability named "cols" defined for linux terminal in terminfo database and u can check it by using command "#infocmp linux" and look in second row for the numeric capability


All times are GMT -5. The time now is 07:14 PM.