🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.shell
Article #106

Re: setting variable from script to current environment??

#106
From: Daniel Smith
Date: Wed, 22 Jul 1992 19:10
54 lines
2291 bytes
In <1992Jul21.070212.16485@gbrmpa.gov.au> wayne@gbrmpa.gov.au (Wayne Amisano) writes:
> I am trying to write a script to set an environment variable in
> my tcsh environment.  I could use an alias to do it, but would
> much rather do it from a script.  What i need to do is, run a
> script to change the value of one environment variable, but
> every time i do this, it changes the variable in the spawned
> process, but it then disappears when it dies.

	You're halfway there.

	Write an alias that *sources* a csh script, and then the
script is free to change any csh or env vars that it wants.

	Here's an example for "pushd":

bermuda:bermuda/qbuild_dansmith (2) :-) alias p
set cd_attempt=(!*); source ~/bin/p_csh

bermuda:bermuda/qbuild_dansmith (2) :-) cat ~/bin/p_csh
#!/bin/echo sorry,try:source
if ($#cd_attempt == 0) set cd_attempt=""
while ($#cd_attempt)
        set o2=$cwd
        set cur_attempt=$cd_attempt[1]
        if ($cur_attempt !~ "") then
                if (! -d $cur_attempt) then
                        set cur_attempt=$cur_attempt:h
                endif
        endif
        pushd $cur_attempt > /dev/null
        echo $cwd
        set old=$o2
        dir_number
        shift cd_attempt
end
prompt_set

and then the aliases for dir_number and prompt_set:

bermuda:bermuda/qbuild_dansmith (2) :-) alias dir_number
set fillstr; set dnum=`dirs`; shift dnum; \
	 if ($#dnum >= 1) set fillstr=" ($#dnum)"

and:

bermuda:bermuda/qbuild_dansmith (2) :-) alias prompt_set
set prompt_head=$cwd:h;set prompt="$HOST"":$prompt_head:t/$cwd:t$fillstr $end "

				Daniel
-- 
            dansmith@autodesk.com            dansmith@well.sf.ca.us
        Daniel Smith, Autodesk, Sausalito, California, (415) 332-2344 x 2580
              Disclaimer: written by a highly caffeinated mammal
 $|=1;for("..."," hacker"," perl"," a","just"){print $l=$_.$l,"\015";sleep 1;}
Technical Details
Message-ID: <17149@autodesk.COM>
Path: arc1-ca.pugleaf.net!sparky!uunet!autodesk!dansmith
References: <1992Jul21.070212.16485@gbrmpa.gov.au>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!autodesk!dansmith
From: dansmith@Autodesk.COM (Daniel Smith)
Newsgroups: comp.unix.shell
Subject: Re: setting variable from script to current environment??
Message-ID: <17149@autodesk.COM>
Date: 22 Jul 92 19:10:40 GMT
References: <1992Jul21.070212.16485@gbrmpa.gov.au>
Organization: Autodesk Inc., Sausalito CA, USA
Lines: 54