From owner-freebsd-questions Thu Jun 28 22:46: 7 2001 Delivered-To: freebsd-questions@freebsd.org Received: from ns2.austclear.com.au (ns2.austclear.com.au [192.43.185.70]) by hub.freebsd.org (Postfix) with ESMTP id 072EB37B409 for ; Thu, 28 Jun 2001 22:46:03 -0700 (PDT) (envelope-from ahl@austclear.com.au) Received: from tungsten.austclear.com.au (tungsten.austclear.com.au [192.168.70.1]) by ns2.austclear.com.au (8.11.2/8.11.3) with ESMTP id f5T5k0p88590; Fri, 29 Jun 2001 15:46:00 +1000 (EST) (envelope-from ahl@austclear.com.au) Received: from tungsten (tungsten [192.168.70.1]) by tungsten.austclear.com.au (8.9.3/8.9.3) with ESMTP id PAA16428; Fri, 29 Jun 2001 15:46:00 +1000 (EST) Message-Id: <200106290546.PAA16428@tungsten.austclear.com.au> X-Mailer: exmh version 2.1.1 10/15/1999 To: "Ian P. Thomas" Cc: jim@freeze.org (Jim Freeze), freebsd-questions@FreeBSD.ORG Subject: Re: How to have a script set an environment variable In-Reply-To: Message from "Ian P. Thomas" of "Thu, 28 Jun 2001 23:56:19 -0400." <200106290356.XAA04190@scraemondaemon.my.domain> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Fri, 29 Jun 2001 15:46:00 +1000 From: Tony Landells 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 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". Of course, the problem with this is that if the "script" is long and sets lots of variables, they finish up in your shell as well. The alternative is to have the script echo the command you want as it's (only) output, and then run that: echo "echo setenv TERM xterm" > /tmp/term_set chmod +x /tmp/term_set eval `/tmp/term_set` which will also set TERM to xterm. There's always a choice ;-) Tony -- Tony Landells Senior Network Engineer Ph: +61 3 9677 9319 Australian Clearing Services Pty Ltd Fax: +61 3 9677 9355 Level 4, Rialto North Tower 525 Collins Street Melbourne VIC 3000 Australia To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message