From owner-freebsd-questions Fri Jun 29 0:39:57 2001 Delivered-To: freebsd-questions@freebsd.org Received: from guru.mired.org (okc-27-141-144.mmcable.com [24.27.141.144]) by hub.freebsd.org (Postfix) with SMTP id 5474637B40D for ; Fri, 29 Jun 2001 00:39:53 -0700 (PDT) (envelope-from mwm@mired.org) Received: (qmail 50178 invoked by uid 100); 29 Jun 2001 07:39:49 -0000 From: Mike Meyer MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <15164.12485.742513.46731@guru.mired.org> Date: Fri, 29 Jun 2001 02:39:49 -0500 To: Tony Landells Cc: questions@freebsd.org Subject: Re: How to have a script set an environment variable In-Reply-To: <15208448@toto.iv> X-Mailer: VM 6.90 under 21.1 (patch 14) "Cuyahoga Valley" XEmacs Lucid X-face: "5Mnwy%?j>IIV\)A=):rjWL~NB2aH[}Yq8Z=u~vJ`"(,&SiLvbbz2W`;h9L,Yg`+vb1>RG% *h+%X^n0EZd>TM8_IB;a8F?(Fb"lw'IgCoyM.[Lg#r\ Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Tony Landells types: > I think that what Jim wants is a script that can "pass an environment > variable back" to the invoking shell. > > No matter what shell you choose, running a shell script (as such) > creates a new shell for the duration of that script, which gets the > environment variable and exits, taking the environment variable with > it. > > All shells support an alternative way of executing commands in a > file which is usually called "sourcing" the file. In sh/ksh/bash/... > it is done by ". commands" (where "commands" is the file containing > the commands to be executed); in csh/tcsh it is done with "source commands". > > So the sequence (in csh or tcsh): > > echo "setenv TERM xterm" > /tmp/term_set > source /tmp/term_set > > will set the TERM environment variable to "xterm". It's normal to use "eval" for that kind of thing: eval `my_tset_script` and then my_tset_scsript looks like: #!/bin/sh case $SHELL in *csh) # use csh syntax echo "setenv VARIABLE=Foo" ;; *) # The default is the sh sentax... echo "export VARIABLE=Foo" ;; esac http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message