 |
|
 |
|
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 |
 |
 |
|
|
 |
|
 |
|
|
 |
Re: How do I bring in ENV |
 |
 |
|
|
|
|
 |
Re: How do I bring in ENV |
 |
 |
|
 |  |  |  |  |
 |
 |
|
Jens.Toerring@physik.fu-berlin.de |
|
|
 |
 |


 |
 |
 |
|  |  |  |  |
|
|
|
 |
|
 |
|
 |
|
|
 |
Re: How do I bring in ENV |
 |
 |
|
|
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 |
 |
 |
|
|
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 |
 |
 |
|
|
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 |
 |
 |
|
|
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 |
 |
 |
|
|
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. |
 |
|
|
 |
|
 |
|
|
 |
|
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
|
 |
|
 |
|