NavigationUser loginSpam?See spam posts on this site? If so, please don't reply to the spam! Instead, just report the URL to the webmaster. |
export questionMaybe I am looking for something I should not see, but if ‘export’
#!/bin/sh
JAVA_HOME='/usr/java/j2re1.4.2_03' export JAVA_HOME
thanks
Tony
|
export question
Tony Heal wrote:
> Maybe I am looking for something I should not see, but if 'export' places a
> variable in the environment shouldn't I be able to see it when using the
> 'set' command. I wrote this small script to test this and nothing shows in
> set. I know I am missing something. If I had the same lines into
> /etc/profile when I log in I see JAVA_HOME in set.
>
>
>
> #!/bin/sh
>
>
>
> JAVA_HOME='/usr/java/j2re1.4.2_03'
>
> export JAVA_HOME
It *is* set in the sub-process created when you run the script.
But that exits. If you execute the shell script in your current
shell, then it will work. For that you use the '.' command. Like
this...
$ cat set_java.sh
#!/bin/sh
JAVA_HOME='/usr/java/j2re1.4.2_03'
export JAVA_HOME
$ ./set_java.sh
$ set | grep JAVA
$ . set_java.sh
$ set | grep JAVA
JAVA_HOME=/usr/java/j2re1.4.2_03
$
I added spaces to make it easier to read.
Mike
--
p="p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
This message made from 100% recycled bits.
You have found the bank of Larn.
I can explain it for you, but I can't understand it for you.
I speak only for myself, and I am unanimous in that!
--
RE: export question
Here is the problem. What you suggest will place the variable in the
environment, but that is what export is supposed to do.
>From the man for bash
export [-fn] [name[=word]] ...
export -p
The supplied names are marked for automatic export to the environment of
subsequently executed commands.
Export should allow me to use the variable in other scripts, but it does not
seem to be doing what it does if used in the profile.
That is what I am confused about.
Tony
-----Original Message-----
From: Mike McCarty [mailto:Mike.McCarty@sbcglobal.net]
Sent: Saturday, January 06, 2007 9:22 PM
To:
Subject: Re: export question
Tony Heal wrote:
> Maybe I am looking for something I should not see, but if 'export' places
a
> variable in the environment shouldn't I be able to see it when using the
> 'set' command. I wrote this small script to test this and nothing shows in
> set. I know I am missing something. If I had the same lines into
> /etc/profile when I log in I see JAVA_HOME in set.
>
>
>
> #!/bin/sh
>
>
>
> JAVA_HOME='/usr/java/j2re1.4.2_03'
>
> export JAVA_HOME
It *is* set in the sub-process created when you run the script.
But that exits. If you execute the shell script in your current
shell, then it will work. For that you use the '.' command. Like
this...
$ cat set_java.sh
#!/bin/sh
JAVA_HOME='/usr/java/j2re1.4.2_03'
export JAVA_HOME
$ ./set_java.sh
$ set | grep JAVA
$ . set_java.sh
$ set | grep JAVA
JAVA_HOME=/usr/java/j2re1.4.2_03
$
I added spaces to make it easier to read.
Mike
--
p="p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
This message made from 100% recycled bits.
You have found the bank of Larn.
I can explain it for you, but I can't understand it for you.
I speak only for myself, and I am unanimous in that!
--
export question
On Sat, Jan 06, 2007 at 10:06:02PM -0500, Tony Heal wrote:
> Here is the problem. What you suggest will place the variable in the
> environment, but that is what export is supposed to do.
>
> >From the man for bash
> export [-fn] [name[=word]] ...
> export -p
> The supplied names are marked for automatic export to the environment of
> subsequently executed commands.
>
> Export should allow me to use the variable in other scripts, but it does not
> seem to be doing what it does if used in the profile.
>
> That is what I am confused about.
>
When you execute your script, a new process is created with your current
shell as its parent. In the *new* process, which starts with a copy of
the parent's environment, the export is executed and it works. Once the
script finishes executing, the *new* process goes away and so do any
changes to the environment. Now, when you *source* the file (i.e., that
is not execute it) it is as though you were typing the commands yourself
in your *current* shell. In that case it will work. Note, however,
that the change is only in effect for that shell and any processes
spawned by it.
Regards,
-Roberto
--
Roberto C. Sanchez
http://people.connexer.com/~roberto
http://www.connexer.com
export question
Tony Heal wrote:
> Here is the problem. What you suggest will place the variable in the
> environment, but that is what export is supposed to do.
>
>>From the man for bash
> export [-fn] [name[=word]] ...
> export -p
> The supplied names are marked for automatic export to the environment of
> subsequently executed commands.
>
> Export should allow me to use the variable in other scripts, but it does not
> seem to be doing what it does if used in the profile.
>
I showed you how to do what you want. I showed that it
does what you want by example. I don't know why you are
arguing with me. The example I gave does exactly what you
just described. If you do what I suggested, subsequent
scripts will see those variables.
> That is what I am confused about.
You wouldn't be confused if you would lift a finger
and try my example for yourself. You are being lazy.
Mike
--
p="p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
This message made from 100% recycled bits.
You have found the bank of Larn.
I can explain it for you, but I can't understand it for you.
I speak only for myself, and I am unanimous in that!
--
RE: export question
I am sorry that you think I was arguing with you. I apologize if it sounded
that way. Yes what you showed me will do what I wanted. But it did not
explain why export was not working. I could do what you suggest, and by
adding another file I can source that file and put the variable into the
environment, but you did not explain why export was not working. Roberto
Sanchez explained that is a subsequent email.
Thank you both for your help. I think I can fix my current issue and
understand where I was going wrong.
Tony
-----Original Message-----
From: Mike McCarty [mailto:Mike.McCarty@sbcglobal.net]
Sent: Sunday, January 07, 2007 3:02 AM
To:
Subject: Re: export question
Tony Heal wrote:
> Here is the problem. What you suggest will place the variable in the
> environment, but that is what export is supposed to do.
>
>>From the man for bash
> export [-fn] [name[=word]] ...
> export -p
> The supplied names are marked for automatic export to the environment
of
> subsequently executed commands.
>
> Export should allow me to use the variable in other scripts, but it does
not
> seem to be doing what it does if used in the profile.
>
I showed you how to do what you want. I showed that it
does what you want by example. I don't know why you are
arguing with me. The example I gave does exactly what you
just described. If you do what I suggested, subsequent
scripts will see those variables.
> That is what I am confused about.
You wouldn't be confused if you would lift a finger
and try my example for yourself. You are being lazy.
Mike
--
This message made from 100% recycled bits.
You have found the bank of Larn.
I can explain it for you, but I can't understand it for you.
I speak only for myself, and I am unanimous in that!
--
export question
On Sat, Jan 06, 2007 at 10:06:02PM -0500, Tony Heal wrote:
> Here is the problem. What you suggest will place the variable in the
> environment, but that is what export is supposed to do.
>
> >From the man for bash
> export [-fn] [name[=word]] ...
> export -p
> The supplied names are marked for automatic export to the environment of
> subsequently executed commands.
>
> Export should allow me to use the variable in other scripts, but it does not
> seem to be doing what it does if used in the profile.
>
> That is what I am confused about.
its all about variable scope.
look at this crappy diagram
bash1--\
|
-- export JAVA
|
-- ./myscript--/bin/sh--\
|
-- bash2--\
|
-- export Java
when you export JAVA in bash1, anything subsequent that you do in
bash1 can see $JAVA. when you execute ./myscript, it spawns a new
shell, bash2. the export of $JAVA in bash2 is totally visible to
anything in bash2, but when that script dies, then bash2 dies and
takes all its variables with it.
at least that's how I understand it. when you source the file '.' as
you've been told, the diagram looks like this.
bash1--\
|
-- export JAVA
|
-- . ./myscript -- export Java
the script doesn't spawn a new shell so the export command is executed
within bash1. when bash1 is exited at some point, then $JAVA will dies
with it.
hth
A
>
> Tony
>
>
>
> -----Original Message-----
> From: Mike McCarty [mailto:Mike.McCarty@sbcglobal.net]
> Sent: Saturday, January 06, 2007 9:22 PM
> To:
> Subject: Re: export question
>
> Tony Heal wrote:
> > Maybe I am looking for something I should not see, but if 'export' places
> a
> > variable in the environment shouldn't I be able to see it when using the
> > 'set' command. I wrote this small script to test this and nothing shows in
> > set. I know I am missing something. If I had the same lines into
> > /etc/profile when I log in I see JAVA_HOME in set.
> >
> >
> >
> > #!/bin/sh
> >
> >
> >
> > JAVA_HOME='/usr/java/j2re1.4.2_03'
> >
> > export JAVA_HOME
>
>
> It *is* set in the sub-process created when you run the script.
> But that exits. If you execute the shell script in your current
> shell, then it will work. For that you use the '.' command. Like
> this...
>
> $ cat set_java.sh
> #!/bin/sh
> JAVA_HOME='/usr/java/j2re1.4.2_03'
> export JAVA_HOME
>
> $ ./set_java.sh
>
> $ set | grep JAVA
>
> $ . set_java.sh
>
> $ set | grep JAVA
>
> JAVA_HOME=/usr/java/j2re1.4.2_03
>
> $
>
> I added spaces to make it easier to read.
>
> Mike
> --
> p="p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
> This message made from 100% recycled bits.
> You have found the bank of Larn.
> I can explain it for you, but I can't understand it for you.
> I speak only for myself, and I am unanimous in that!
>
>
> --