How do I bring in ENV
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > How do I bring in ENV




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    How do I bring in ENV  
Billy N. Patton


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-12-04 04:34 AM

How do I bring in environment variables into a shell?

In a csh I can do a source my_file

Here's an example
file -> init
#!/usr/bin/sh
set -x;
TOOLBOX=some_path;
export TOOLBOX;

file -> go
#!/usr/bin/sh
set -x
printf "This is sh\n";

eval init gs40;

echo "TOOLBOX : '$TOOLBOX'";

exec "perl"<<DO_PERL

use Data::Dumper;

@_ = qw ( This is PERL );

print Dumper(\@_);
print "TOOLBOX = '$ENV{TOOLBOX}'\n";

DO_PERL;

printf "This is sh again\n";
echo "TOOLBOX : '$TOOLBOX'"





WHere the eval init it will eval the file but the TOOLBOX variable does
not exists.

I've tried exec init but the script stops after the exec.

How can I get the variables exported int he init script into the current
environment?


here is from the man page
sh
The exec command specified by the arguments is  executed  in
place   of  this  shell  without  creating  a  new  process.
Input/output arguments may appear and, if no other arguments
are given, cause the shell input/output to be modified.

The arguments to the eval built-in are read as input to  the
shell and the resulting command(s) executed.

--
___  _ ____       ___       __  __
/ _ )(_) / /_ __  / _ \___ _/ /_/ /____  ___
/ _  / / / / // / / ___/ _ `/ __/ __/ _ \/ _ \
/____/_/_/_/\_, / /_/   \_,_/\__/\__/\___/_//_/
/___/
Texas Instruments ASIC Circuit Design Methodlogy Group
Dallas, Texas, 214-480-4455,  b-patton@ti.com






[ Post a follow-up to this message ]



    Re: How do I bring in ENV  
Jens.Toerring@physik.fu-berlin.de


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-12-04 05:34 AM

Billy N. Patton <b-patton@ti.com> wrote:
> How do I bring in environment variables into a shell?

> In a csh I can do a source my_file

> Here's an example
> file -> init
> #!/usr/bin/sh
> set -x;
> TOOLBOX=some_path;
> export TOOLBOX;

export TOOLBOX=some_path

will also do.

> I've tried exec init but the script stops after the exec.

Of course, because the shell gets _replaced_ by the script (running in its
own shell) and when it's done you don't get back into the old shell (which
does not exist anymore).

> How can I get the variables exported int he init script into the current
> environment?

You do the same in (ba)sh as in csh, you just source the 'init' script
instead of running it by

# . init

or, in the long version

# source init
Regards, Jens
--
\   Jens Thoms Toerring  ___  Jens.Toerring@physik.fu-berlin.de
\__________________________  http://www.physik.fu-berlin.de/~toerring





[ Post a follow-up to this message ]



    Re: How do I bring in ENV  
Jeff Schwab


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-12-04 05:34 AM

Jens.Toerring@physik.fu-berlin.de wrote:
> Billy N. Patton <b-patton@ti.com> wrote:
> 
>
> 
>
> 
>
>
> export TOOLBOX=some_path
>
> will also do.

Only in Bash.  On most Unices, only the long form is correct.  On Linux,
of course, "sh" is really bash, so both forms work.






[ Post a follow-up to this message ]



    Re: How do I bring in ENV  
Jens.Toerring@physik.fu-berlin.de


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-12-04 05:34 AM

Jeff Schwab <jeffplus@comcast.net> wrote:
> Jens.Toerring@physik.fu-berlin.de wrote: 

> Only in Bash.  On most Unices, only the long form is correct.  On Linux,
> of course, "sh" is really bash, so both forms work.

Thanks, I probably should try to get a "real" sh, the above works the
bash way even if it's invoked as sh (which I did assume to make bash
more sh-like but which mostly seems to just change the start-up
behaviour as I found out after I now took a closer look).

Regards, Jens
--
\   Jens Thoms Toerring  ___  Jens.Toerring@physik.fu-berlin.de
\__________________________  http://www.physik.fu-berlin.de/~toerring





[ Post a follow-up to this message ]



    Re: How do I bring in ENV  
Fletcher Glenn


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-12-04 12:36 PM



Billy N. Patton wrote:
> How do I bring in environment variables into a shell?
>
> In a csh I can do a source my_file
>
> Here's an example
> file -> init
> #!/usr/bin/sh
> set -x;
> TOOLBOX=some_path;
> export TOOLBOX;
>
> file -> go
> #!/usr/bin/sh
> set -x
> printf "This is sh\n";
>
> eval init gs40;
>
> echo "TOOLBOX : '$TOOLBOX'";
>
> exec "perl"<<DO_PERL
>
> use Data::Dumper;
>
> @_ = qw ( This is PERL );
>
> print Dumper(\@_);
> print "TOOLBOX = '$ENV{TOOLBOX}'\n";
>
> DO_PERL;
>
> printf "This is sh again\n";
> echo "TOOLBOX : '$TOOLBOX'"
>
>
>
>
>
> WHere the eval init it will eval the file but the TOOLBOX variable does
> not exists.
>
> I've tried exec init but the script stops after the exec.
>
> How can I get the variables exported int he init script into the current
> environment?
>
>
> here is from the man page
>   sh
>      The exec command specified by the arguments is  executed  in
>      place   of  this  shell  without  creating  a  new  process.
>      Input/output arguments may appear and, if no other arguments
>      are given, cause the shell input/output to be modified.
>
>      The arguments to the eval built-in are read as input to  the
>      shell and the resulting command(s) executed.
>

In many shells, anything enclosed in single quotes is immune to
variable substitution.

--

Fletcher Glenn






[ Post a follow-up to this message ]



    Re: How do I bring in ENV  
Michael Kerrisk


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-12-04 11:34 PM

On Thu, 12 Feb 2004 08:18:15 -0500, Jeff Schwab <jeffplus@comcast.net>
wrote:

>Jens.Toerring@physik.fu-berlin.de wrote: 
>
>Only in Bash.  On most Unices, only the long form is correct.  On Linux,
>of course, "sh" is really bash, so both forms work.

This is simply not true.  POSIX specifies both forms, and IIRC
correctly, in early Bourne shells, it was the LONG form that couldn't
be used.

Cheers,

Michael





[ Post a follow-up to this message ]



    Re: How do I bring in ENV  
Chris F.A. Johnson


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-13-04 12:35 AM

On Fri, 13 Feb 2004 at 07:38 GMT, Michael Kerrisk wrote:
> On Thu, 12 Feb 2004 08:18:15 -0500, Jeff Schwab wrote: 
[snip] 
>
> This is simply not true.  POSIX specifies both forms, and IIRC
> correctly, in early Bourne shells, it was the LONG form that couldn't
> be used.

Which are you calling the LONG form?

TOOLBOX=some_path; export TOOLBOX

export TOOLBOX=some_path

The latter (which looks shorter to me) is specified in POSIX, and
works in ksh (pd, 88 and 93) as well as bash and ash (as in
FreeBSD sh), but not in a Bourne shell.

--
Chris F.A. Johnson                        http://cfaj.freeshell.org
 ========================================
===========================
My code (if any) in this post is copyright 2004, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License





[ Post a follow-up to this message ]



    Re: How do I bring in ENV  
Michael Kerrisk


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-15-04 11:33 PM

On 13 Feb 2004 08:31:11 GMT, "Chris F.A. Johnson"
<c.fa.johnson@rogers.com> wrote:

>On Fri, 13 Feb 2004 at 07:38 GMT, Michael Kerrisk wrote: 
>[snip] 
>
>     Which are you calling the LONG form?

GOod popint -- I may have completely misunderstood
the previous poster!

By Long, I was thinking of

expot NAME=VALUE

Of course it's clear to me (now) that someone could easily
understand the long form to refer to the other syntax.

>TOOLBOX=some_path; export TOOLBOX
>
>export TOOLBOX=some_path
>
>     The latter (which looks shorter to me) is specified in POSIX, and
>     works in ksh (pd, 88 and 93) as well as bash and ash (as in
>     FreeBSD sh), but not in a Bourne shell.

Agreed.  And sorry for the confusion.

Cheers,

Michael





[ Post a follow-up to this message ]



    Re: How do I bring in ENV  
Bill Marcum


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-28-04 09:34 PM

On Thu, 12 Feb 2004 06:49:12 -0600, Billy N. Patton
<b-patton@ti.com> wrote:
>
> WHere the eval init it will eval the file but the TOOLBOX variable does
> not exists.
>
> I've tried exec init but the script stops after the exec.
>
Naming a program "init" is almost as bad as "test", except that "init"
will probably only cause trouble if you are root.


--
Incrsease your earoning poswer and gaerner profwessional resspect.
Get the Un1iversity Dewgree you have already earned.
[from the prestigious, non-accredited university of Spam!]





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 07:26 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register