Path: utzoo!attcan!uunet!bu.edu!rpi!leah!cook!percival!narten From: narten@percival.albany.edu (Thomas Narten) Newsgroups: comp.windows.x Subject: Re: Setting up DISPLAY environment variable Message-ID: <143@percival.albany.edu> Date: 30 Jun 90 14:15:50 GMT Organization: SUNY Albany, Comp. Sci. Dept, Albany, NY Lines: 76 In article <9173@uswat.UUCP> bar@uswat.uswest.com (Bala Ramakrishnan 595-2868) writes: >My .cshrc file has : setenv DISPLAY localhost:0 > >However, when I rlogin to the sparc server, the same .cshrc file gets >executed and DISPLAY is set to localhost:0. When I am on the sparc >server, my .cshrc file should set DISPLAY to :0 Setting DISPLAY in either .cshrc or .login is asking for trouble. Here is what I do. It works well, and handles all the nice cases (e.g., when I'm logged in through an ascii terminal, DISPLAY does not get set). First, you only want to set DISPLAY to be the name of where your X server is running. The best place to set it is in your .xinitrc file, which is executed only when you start up the X server. Here are relevant lines from my .xinitrc: # Check to see if the DISPLAY environment variable is set. If not, # then set it to "unix:0" DISPLAY=${DISPLAY-unix:0}; export DISPLAY In addition, you may also want to be able to run other X applications on remote machines that open connections directly with your server. To start emacs on a remote machine for instance, my .twmrc looks like: "Emacs@atanasoff" !"xrsh atanasoff emacs -in Emacs@atansoff -wn Emacs@atanasoff &" Finally, xrsh does the same thing as rsh, except that: 1) it uses xhosts to allow the remote machine to create windows on the machine running your server 2) it sets the DISPLAY variable on the remote machine to point back to your server before running the actual program. #!/bin/sh # # A frontend to rsh to start an X client on another host. # # A version of this was originally posted to Usenet in # 12/88 by Chris Torek (chris@mimsy.umd.edu). # Enhanced by Marion Hakanson (hakanson@cse.ogc.edu). # $Id: xrsh,v 1.8 89/10/13 14:06:35 hakanson Rel $ # # Simply exports $DISPLAY, and runs the given command. # # Uses /bin/sh to factor out the user's default remote shell. # Redirects I/O to allow rsh & rshd to exit immediately, and uses # exec, both in order to minimize the number of processes involved. # # Set "out" to /dev/null if you don't care to have access to # diagnostics from the last xrsh invocation on target machine. case $# in 0|1) echo "usage: $0 host cmd [args]" 1>&2; exit 1;; esac : ${DISPLAY?"environment variable DISPLAY not set"} case "X$DISPLAY" in Xunix:*) : ${HOSTNAME=`hostname`} DISPLAY=`echo "$DISPLAY" | sed -e "s/^unix:/${HOSTNAME}:/"` ;; X:*) : ${HOSTNAME=`hostname`} DISPLAY="$HOSTNAME$DISPLAY" ;; esac host="$1" shift out=".xrsh.out" xhost $host >/dev/null rsh "$host" -n exec /bin/sh -c \ "'DISPLAY=\"$DISPLAY\"; export DISPLAY; exec $@ $out 2>&1'" -- Thomas Narten narten@cs.albany.edu