🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.shell
Article #148

Re: setting variable from script to current environment??

#148
From: Daniel Smith
Date: Fri, 24 Jul 1992 22:37
43 lines
1951 bytes
In <1992Jul23.191928.4948@walter.bellcore.com> snk@fork.bae.bellcore.com (Samuel N Kamens) writes:
> One thing to be careful of when you source shells -- if those shells
> have an "exit" in them, that will cause the *PARENT* process to exit.

> I can't count how many times I have sourced a file that did an exit
> and watched my xterm disappear..... :-(


	Right, a good thing to do is have a label to go to at the end:

#!/bin/echo sorry,try:source
if ($#newdir_attempt == 0) then
        echo 'usage: newdir dir_to_make [files to move to dir_to_make]'
        goto nd_end
endif
 
mkdir $newdir_attempt[1] || goto nd_end
set cd_attempt=$newdir_attempt[1]
if ($#newdir_attempt > 1) then
        shift newdir_attempt
        mv -f $newdir_attempt $cd_attempt
        unset newdir_attempt
endif
pl $cd_attempt
 
nd_end:


	this example makes a directory, moves any files you specify
into it, and pushd's the new directory (the pl alias).  Called as:

alias newdir 'set newdir_attempt=(\!*); source ~/bin/newdir_csh'

	It's probably good practice to call the end labels something
different in each script, or you may confuse the shell as to which
"end:" you mean.

				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: <17223@autodesk.COM>
Path: arc1-ca.pugleaf.net!sparky!uunet!autodesk!dansmith
References: <1992Jul21.070212.16485@gbrmpa.gov.au> <1992Jul22.014834.1384@jpradley.jpr.com> <1992Jul23.191928.4948@walter.bellcore.com>

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: <17223@autodesk.COM>
Date: 24 Jul 92 22:37:48 GMT
References: <1992Jul21.070212.16485@gbrmpa.gov.au> <1992Jul22.014834.1384@jpradley.jpr.com> <1992Jul23.191928.4948@walter.bellcore.com>
Organization: Autodesk Inc., Sausalito CA, USA
Lines: 43