Operating System - HP-UX
1823143 Members
3568 Online
109647 Solutions
New Discussion юеВ

Set TERM value with tty command

 
SOLVED
Go to solution
george_114
Advisor

Set TERM value with tty command

Please help me, I am newbie in Unix.
I have a case when i execute command tty on console:
$tty
/dev/tty1 or /dev/tty2 or etc

And when i execute command tty on client machine:
$tty
/dev/pts/0 or /dev/pts/1 or etc

How to make a script that can set $TERM in two conditions:
if tty=/dev/tty* then set $TERM=vt100
else set $TERM=ansi

Thanks in advance for your help.

9 REPLIES 9
Elmar P. Kolkman
Honored Contributor

Re: Set TERM value with tty command

if tty | grep -q /pts/
then
TERM=ansi
else
TERM=vt100
fi

export TERM
Every problem has at least one solution. Only some solutions are harder to find.
Graham Cameron_1
Honored Contributor

Re: Set TERM value with tty command

Elmar is right, but there may be better ways.

There is a file called "/etc/ttytype" (see man 4 ttytype) into which you can put these values, one line per terminal.
Then in your profile, add a "tset" command which reads the file and sets the TERM.

Alternatively, there is a command, also called ttytype (see man 1 ttytype), which interrogates your terminal and decides what type it is. You can use the output to set the TERM variable, using eval `ttytype -s`

-- Graham
Computers make it easier to do a lot of things, but most of the things they make it easier to do don't need to be done.
george_114
Advisor

Re: Set TERM value with tty command

hi Elmar, i have put your script to text file called trm and run it but it does not take effect to my TERM value.
Graham Cameron_1
Honored Contributor

Re: Set TERM value with tty command

George

You need to put the commands into your .profile in your home directory, and log in again.

Or save to a textfile, and say ". ./textfile".
Note - dot space dot slash -- important

-- Graha,
Computers make it easier to do a lot of things, but most of the things they make it easier to do don't need to be done.
Elmar P. Kolkman
Honored Contributor

Re: Set TERM value with tty command

Graham is right. If you call your script in a normal way, the environment variable is changed for that instance of your shell and its children. You want to change it for your current shell, so you have to run the commands with that shell. This can be done by calling the script with Graham's syntax,
'. ./trm' in your case. Or put the lines in your .profile. Calling trm from your .profile will not work either.

The problem with using the ttytype database is that you have to specify a line for every tty possible... Or you use a default if it is not in the file, which means you have to only specify /dev/tty* entries as being vt100 and if your tty is not in /etc/ttytype it will be ansi.

I hope this answer is better then the previous one ...
Every problem has at least one solution. Only some solutions are harder to find.
george_114
Advisor

Re: Set TERM value with tty command

Hi Graha, I have done your advice but still not take any effect, why ??
below is it's history:
$tty
/dev/pts/0
$TERM=vt100;export TERM
$ ./trm
$ echo $TERM
vt100
more trm
if tty | grep -q /pts/
then
TERM=ansi
else
TERM=vt100

export TERM
Elmar P. Kolkman
Honored Contributor

Re: Set TERM value with tty command

You miss a '. ' when calling trm.
Every problem has at least one solution. Only some solutions are harder to find.
george_114
Advisor

Re: Set TERM value with tty command

Hi Elmar, i have put . when i run this script like $ ./trm but still not make any effect.Why ????
Elmar P. Kolkman
Honored Contributor
Solution

Re: Set TERM value with tty command

You run it from the current directory by using the './' (dot slash), but to run it in your current shell, you have to add '. ' (dot space). Graham put that info in his first post too.
Every problem has at least one solution. Only some solutions are harder to find.