home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.shell
- Path: sparky!uunet!munnari.oz.au!sgiblab!spool.mu.edu!yale.edu!ira.uka.de!math.fu-berlin.de!mailgzrz.TU-Berlin.DE!news.netmbx.de!Germany.EU.net!mcsun!sunic!palantir.p.tvt.se!infolog!mich
- From: mich@lin.infolog.se (Thomas Michanek)
- Subject: Re: Setting enviroment variables in a shell script
- Message-ID: <1993Jan26.091447.2303@infolog.se>
- Keywords: environment variables shell script
- Sender: news@infolog.se
- Organization: Infologics, Linkoping, Sweden
- References: <35774@sales.GBA.NYU.EDU> <1993Jan25.003213.3784@lri.fr> <18469@autodesk.COM>
- Date: Tue, 26 Jan 1993 09:14:47 GMT
- Lines: 38
-
- In article <18469@autodesk.COM> dls@Autodesk.COM (Daniel Louis Smith) writes:
- >
- >> In article <35774@sales.GBA.NYU.EDU>, elouie@sales.GBA.NYU.EDU (Euge) writes:
- >> |> How do you set an environment variable in a C-Shell script? I tried
- >> |> setenv enviroment_variable value, but as soon as the script finishes,
- >> |> the value of the varialbe is reset to its original value. My guess is
- >
- > My favorite way is to source bits of csh... example:
- >
- >bermuda:dls/bin (1) :-) alias newdir
- >set newdir_attempt=(!*); source $HOME/bin/newdir_csh
- >
-
-
- Good idea, except that you don't have to use a separate variable to
- store the command line arguments. In general, you can make an alias like:
-
- alias <name> "source <filename> '\!*'"
-
- In the source'd file <filename> you put:
-
- set argv = `echo \!*`
-
- as the first command. You can now use $1, $2, etc. as in an ordinary script:
-
- if ($#argv > 0) then
- setenv MYVAR $1 # or whatever
- ...
- endif
-
- Works like a dream!
-
- .- - - - - - - - - - - -. _ _ _ ___ _ _ _ _ _ _ _ .- - - - - - - -.
- | Thomas Michanek | | |\ | |_ / \ | / \ / _ | / `|_` | Dial +46 13 |
- | Infologics Linkoping | | | \| | \_/ |_,\_/ \_| | \_,._| | 210060 Phone |
- | email:Thomas.Michanek | _ | 210068 Direct|
- | @lin.infolog.se | L I N K O P I N G - S W E D E N | 210155 Fax |
- `- - - - - - - - - - - -' `- - - - - - - -'
-