SUMMARY: the DISPLAY environment on remote machines

From: Clive Haworth (
Date: Thu Dec 16 1993 - 17:55:22 CST

Original Posting

> Here's something I came across recently, wish may be of some use
> to someone. I seem to remember someone asking for this - but have
> forgotten who & when.
> Basically adding this to your .login file will set the DISPLAY
> environment automatically to your own display. It seems to work
> OK but I haven't tested it extensively.
> #
> # Set DISPLAY automatically on login (csh version).
> #
> set COMEFROM = \
> `who am i | awk '{print $6}' | tr -d '()' | awk -F. '{print $1}'`
> if ( $#COMEFROM == 1 ) then
> setenv DISPLAY ${COMEFROM}:0
> endif
> unset COMEFROM

I had a good response to this one, with lots of ideas.
Many thanks to the following people that responded to this:

 James D. Watson <>
 Ben Gross <>
 Calum Mackay <>
 Dave Hightower <>
 James J Dempsey <> (Peter Samuel)
 Yves Morin <Yves.Morin@BComeau.Hydro.Qc.CA>
 bern@kleopatra.Uni-Trier.DE (Jochen Bern) (Frank Greco) (Scott W Fischer) (Sumner Hushing) (Leon Koll) (Mark C. Henderson)
 aluxpo!nlf (Nelson Fernandez) (Olav Lerbrekk)

Most people pointed out that the trick only works for the first hop.
The next hop sets the DISPLAY incorrectly.

Others pointed out that 'who' is fairly specific to whatever breed of
UNIX you're running. Scott W Fischer sent a C program to emulate the
above script, though this still suffers from the hop problem.

Nelson Fernandez suggested packing information into the TERM environment
variable to solve this problem. Also xlogin or xrsh was suggested.

My preferred choice was suggested by Peter Samuel:

> A better (but still not perfect way) is to save the value of $DISPLAY
> as generated by ~/.xinitrc or ~/.xsession in a file ~/.display and then
> get your shell to read the file on login and set $DISPLAY from the file's
> contents.
> This method works very well - regardless of the number of hops you
> make around your network.
> It fails if you are logged into two different X displays
> simultaneously because the second login will overwrite the contents of
> ~/.display.

I chose a simple form of this - to create a file .Xdisplay
in my home directory:

# The display to view X applications on when remotely logged in.

Then add these lines to the login script:

if ( -f $HOME/.Xdisplay ) then
        # Set the DISPLAY environment variable if possible.
        # Allow comment characters '#' at the start of a line.
        setenv DISPLAY "`egrep -v '^#' $HOME/.Xdisplay`"

Thanks again for the response !!

Clive Haworth

This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:08:33 CDT