Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!purdue!bu-cs!buengc!bph From: bph@buengc.BU.EDU (Blair P. Houghton) Newsgroups: comp.unix.questions Subject: Re: DISPLAY environment variable from login(1) Message-ID: <4065@buengc.BU.EDU> Date: 7 Sep 89 19:47:32 GMT References: <4045@buengc.BU.EDU> <2273@marvin.Solbourne.COM> <4599@ogccse.ogc.edu> <2284@marvin.Solbourne.COM> Reply-To: bph@buengc.bu.edu (Blair P. Houghton) Followup-To: comp.unix.questions Organization: Boston Univ. Col. of Eng. Lines: 111 In article <2284@marvin.Solbourne.COM> dce@Solbourne.com (David Elliott) writes: >In article <4599@ogccse.ogc.edu> schaefer@ogccse.UUCP (Barton E. Schaefer) writes: >>So, you create a front-end script on the local machine that looks like > >The solution outlined here is quite reasonable in many cases, and I >used it for about a day. Very nice, guys. I appreciate the help greatly. However, me and a couple of other guys came up with an even better hack (well, they found it, I kludged it). There's an _undocumented_ flag '-p' to the login(1) in Ultrix 3.1 (nee 3.0) that preserves the environment across the login-procedure. The only trick is to elide every other shell and environment variable without losing DISPLAY. Don't let that "undocumented is unsupported" stuff fool you. If it works in this version, it works in this version. There isn't even a guarantee that login(1) will exist in the next rev. of the OS. Here's the script. I use it about twenty times a day. --Blair "It woiks!!" P.S. One comment I left out of the code: I couldn't get 'unsetenv *' to work. It should. It don't. Hence the eval of the sed script output. Hackitty-hack-hack... :-) ---------------------------->8 Clip 'n' bolog! 8<-------------------- #!/bin/sh # # This is a shell archive. To extract its contents, # execute this file with /bin/sh to create the files: # bolog # # This shell archive created: Tue Sep 5 04:19:34 EST 1989 # echo "extracting file bolog" sed -e 's/^X//' <<\*EOF > bolog X#! /bin/csh -f X X# X# Bolog -- the C-shell script that keeps your DISPLAY in scope X# through a login(1) execution. X# X# (C) 1989 Blair P. Houghton, All Rights Reserved X# Distribute freely, but keep my name attached. X# X# ULTRIX belongs to DEC, and UMAX belongs to Encore. This X# script was tested under Ultrix 3.1. X# X X# X# This loop will work, but only by fixing it to echo the "set" X# commands to a file, then sourcing the file, since the X# loop actually is a subshell...All we really intend X# to propagate is the DISPLAY variable, anyway... X# X#foreach i ( $* ) X# set $i=`printenv $i` X#end X X# X# Protect DISPLAY from total unsetenv X# X Xset DISPLAY=`printenv DISPLAY` X X# X# Wipe out all environment variables; requires cut(1), X# which comes with Ultrix, but not Umax but is in X# PD archives, so may be in a ...local/bin directory. X# X Xeval `printenv | cut -f1 -d"=" | sed -e '1,$s/^/unsetenv /'` X X# X# Put DISPLAY where it belongs, since it's impossible X# to inform the shell after the login to do so. X# X Xsetenv DISPLAY $DISPLAY X X# X# Wipe out all shell variables, which may also get passed X# and not superseded. X# X Xunset * X X# X# Paths have also been unset. Replace this process with the login. X# When login is done (i.e., via logout), control will X# be returned to the parent of this process. If this X# process is run as argument to the -e flag of xterm(1X), X# then the xterm is the parent, and will immediately exit X# when this process returns. X# X# NOTE: this uses an undocumented, and therefore X# unsupported, flag ('-p') to the login(1) X# command. I owe this knowledge to Peter Morreale X# of NCAR, and Guy Cardwell of UCI. --Blair X# X Xexec /bin/login -p *EOF if [ `wc -c