[comp.unix.questions] Shell variables - help

mchetan@hawk.ulowell.edu (Munisuvratha Chetan) (10/08/90)

I have a shell program that sets certain shell variables
according to certain working environment.  If I execute this
program after logging in, the login shell does not have those
variables (of course, because the shell program is executed in
a new shell).
How do I tell the current shell to execute the shell program in
the current shell, and NOT in a new shell ?
Or, isn't there any such mechanism ?

Thanx a bunch.

ronald@atcmp.nl (Ronald Pikkert) (10/10/90)

From article <1339@ul-cs.ulowell.edu>, by mchetan@hawk.ulowell.edu (Munisuvratha Chetan):

> How do I tell the current shell to execute the shell program in
> the current shell, and NOT in a new shell ?

The command: . ./foo will execute the script named foo in the current
                     directory without starting a subshell to do the job.


-
Ronald Pikkert                 E-mail: ronald@atcmp.nl
@ AT Computing b.v.            Tel:    080 - 566880
Toernooiveld
6525 ED  Nijmegen

hunt@dg-rtp.rtp.dg.com (Greg Hunt) (10/10/90)

In article <1339@ul-cs.ulowell.edu>, mchetan@hawk.ulowell.edu
(Munisuvratha Chetan) writes:
> I have a shell program that sets certain shell variables
> according to certain working environment.  If I execute this
> program after logging in, the login shell does not have those
> variables (of course, because the shell program is executed in
> a new shell).
> How do I tell the current shell to execute the shell program in
> the current shell, and NOT in a new shell ?
> Or, isn't there any such mechanism ?
> 
> Thanx a bunch.
> 

If the script is a bourne shell script (designed for /bin/sh), then 
you do the following:

    . name_of_script

This is a period followed by a space followed by the name of your
script.

If the script is a C shell script (designed for /bin/csh), then you
do the following:

    source name_of_script

I don't know how other shells (like ksh) handle this.

Enjoy!

--
Greg Hunt                        Internet: hunt@dg-rtp.rtp.dg.com
DG/UX Kernel Development         UUCP:     {world}!mcnc!rti!dg-rtp!hunt
Data General Corporation
Research Triangle Park, NC       These opinions are mine, not DG's.

gwyn@smoke.BRL.MIL (Doug Gwyn) (10/11/90)

In article <1339@ul-cs.ulowell.edu> mchetan@hawk.ulowell.edu (Munisuvratha Chetan) writes:
>How do I tell the current shell to execute the shell program in
>the current shell, and NOT in a new shell ?

Use the "." builtin command:
	. foo_bar	# executes foo_bar script in the current shell

bob@wyse.wyse.com (Bob McGowen x4312 dept208) (10/11/90)

In article <1339@ul-cs.ulowell.edu> mchetan@hawk.ulowell.edu (Munisuvratha Chetan) writes:
>I have a shell program that sets certain shell variables
>according to certain working environment.  If I execute this
....
>How do I tell the current shell to execute the shell program in
>the current shell, and NOT in a new shell ?

try using the dot command in sh or source in csh:

For sh:
   . file # the current shell reads file and runs it,
	  # file need not be executable

For csh:
   source file # current shell read and runs file,
	       # also does not need execut permissions

In sh (maybe also csh, I do not know), if you are running as root and
the root path does not inlcude the current directory (which is good
security practice), you will need to use the dot command as follows:

   . ./file # provides a relative path pointed at the file

Bob McGowan  (standard disclaimer, these are my own ...)
Product Support, Wyse Technology, San Jose, CA
..!uunet!wyse!bob
bob@wyse.com

cpcahil@virtech.uucp (Conor P. Cahill) (10/11/90)

In article <1339@ul-cs.ulowell.edu> mchetan@hawk.ulowell.edu (Munisuvratha Chetan) writes:
>How do I tell the current shell to execute the shell program in
>the current shell, and NOT in a new shell ?

What you need to do is "source" the sub-shell.  The way you do this
varies depending upon which shell you are talking about.  Both the Korn (ksh)
and Bourne (sh) shells use ".".  So if you wanted to re-run your .profile
and have its settings apply to your current shell you would enter:

	. ./.profile

-- 
Conor P. Cahill            (703)430-9247        Virtual Technologies, Inc.,
uunet!virtech!cpcahil                           46030 Manekin Plaza, Suite 160
                                                Sterling, VA 22170 

sweh@tharr.UUCP (Stephen Harris) (10/13/90)

In article <669@atcmpe.atcmp.nl> ronald@atcmp.nl (Ronald Pikkert) writes:
RP>From article <1339@ul-cs.ulowell.edu>, by mchetan@hawk.ulowell.edu (Munisuvratha Chetan):
RP>
RP>> How do I tell the current shell to execute the shell program in
RP>> the current shell, and NOT in a new shell ?
RP>
RP>The command: . ./foo will execute the script named foo in the current
RP>                     directory without starting a subshell to do the job.
RP>
And in C-shell use the command
	source ./foo
to do the same thing.

RP>
RP>-
-- 
    			     Stephen Harris
Disclaimer: me have an opinion?     | Email: ..!ukc!axion!tharr!sweh
            What an idea!	    |        sweh%tharr.uucp@uk.co.bt.axion
Wanted: humour transplant           |        tharr!sweh@uk.ac.ukc 
     <-- tharr *free* public access to Usenet in the UK 0234 261804 -->

emanuele@overlf.UUCP (Mark A. Emanuele) (10/13/90)

In article <1339@ul-cs.ulowell.edu>, mchetan@hawk.ulowell.edu (Munisuvratha Chetan) writes:
> How do I tell the current shell to execute the shell program in
> the current shell, and NOT in a new shell ?


Correct me if I am wrong, but I think this will work.


	. shell-program-name-that-is-executible

This should execute that shell script in the current shell much like the way
your .profile does.


-- 
Mark A. Emanuele
V.P. Engineering  Overleaf, Inc.
500 Route 10 Ledgewood, NJ 07852-9639         attmail!overlf!emanuele
(201) 927-3785 Voice   (201) 927-5781 fax     emanuele@overlf.UUCP

george@hls0.hls.oz (George Turczynski) (10/15/90)

In article <1339@ul-cs.ulowell.edu>, mchetan@hawk.ulowell.edu (Munisuvratha Chetan) writes:
> I have a shell program that sets certain shell variables
> according to certain working environment.  If I execute this
> program after logging in, the login shell does not have those
> variables (of course, because the shell program is executed in
> a new shell).
> How do I tell the current shell to execute the shell program in
> the current shell, and NOT in a new shell ?
> Or, isn't there any such mechanism ?
> 
> Thanx a bunch.

What SHELL are you using ???

Oh well, use "source <filename>" in the C-SHELL (/bin/csh)
and ". <filename>" in the BOURNE-SHELL (/bin/sh).

Also, RTFM.

And by the way, is this on the FAQ list ?  If not perhaps it
should be.

-- 
George P. J. Turczynski,   Computer Systems Engineer. Highland Logic Pty Ltd.
ACSnet: george@highland.oz |^^^^^^^^^^^^^^^^^^^^^^^^| Suite 1, 348-354 Argyle St
Phone:  +61 48 683490      |  Witty remarks are as  | Moss Vale, NSW. 2577
Fax:    +61 48 683474      |  hard to come by as is | Australia.
---------------------------   space to put them !    ---------------------------