Re: Question re. export environment variable
On Thu, 20 Feb 2003, Fred Ma wrote: Hello, I'm using cygwin bash 2.05b-8 (it's actually gnu). I thought that $HOSTNAME was an environment variable. When I run gnu make (I'm pretty sure this is not a make problem), $(HOSTNAME) is empty. It gets fixed if I do export HOSTNAME before running make. Is there a way to check if the export command has been applied to $HOSTNAME? Does the actual transcription of $HOSTNAME's value to the environment happen only once, when export is applied, or is there a continual monitoring an mirroring of changes to $HOSTNAME forever after applying export? Fred Fred, I'm afraid you might be confused about what exporting a variable means. Bash maintains an environment, which contains the values of all the variables it's using. When bash spawns a child, that child inherits those variables from the parent's environment that are exported. Thus, if you export HOSTNAME, the child will get the current value of HOSTNAME. If you then change HOSTNAME in the parent, the child *will not* see the change. However, if you spawn another child, that new child *will* see the new value. BTW, export with no variable name will print out the list of all variables that are exported from the current shell. And, if you want to make sure it's exported, export HOSTNAME can do no harm. But both this and the above are off-topic for the Cygwin list, and could have been found by a simple perusal of man bash. Igor -- http://cs.nyu.edu/~pechtcha/ |\ _,,,---,,_[EMAIL PROTECTED] ZZZzz /,`.-'`'-. ;-;;,_[EMAIL PROTECTED] |,4- ) )-,_. ,\ ( `'-' Igor Pechtchanski '---''(_/--' `-'\_) fL a.k.a JaguaR-R-R-r-r-r-.-.-. Meow! Oh, boy, virtual memory! Now I'm gonna make myself a really *big* RAMdisk! -- /usr/games/fortune -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Bug reporting: http://cygwin.com/bugs.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/
Re: Question re. export environment variable
Fred, perhaps this will help: echo $TEST # Test has no value, hence the blank line. $ TEST=noexport # Set but not exported $ echo $TEST noexport $ env|grep TEST # Nothing found, no output. $ export TEST # Export it. $ env|grep TEST # And now it's found in the environment. TEST=noexport $ TEST=second # Change its value. $ env|grep TEST # Same search as above, but the value is changed. TEST=second Perhaps the easiest way to look at it is to think of exporting as making a type of global variable. Everyone (within certain limits; for the shell, only its children...) will see the exported variable. If the value changes, it changes everywhere. I've quoted everywhere because this only applies to children invoked after the change. So if TEST=second and you run an xterm, the new shell sees TEST=second. Change TEST=third in the first shell, you still have TEST=second in the second shell, since it already got its value for TEST. Start a third shell from the first, it will see TEST=third. And so on. Fred Ma wrote: Hello, I'm using cygwin bash 2.05b-8 (it's actually gnu). I thought that $HOSTNAME was an environment variable. When I run gnu make (I'm pretty sure this is not a make problem), $(HOSTNAME) is empty. It gets fixed if I do export HOSTNAME before running make. Is there a way to check if the export command has been applied to $HOSTNAME? Does the actual transcription of $HOSTNAME's value to the environment happen only once, when export is applied, or is there a continual monitoring an mirroring of changes to $HOSTNAME forever after applying export? Fred -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Bug reporting: http://cygwin.com/bugs.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/ -- Bob McGowan Staff Development Engineer VERITAS Software [EMAIL PROTECTED] -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Bug reporting: http://cygwin.com/bugs.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/
Re: Question re. export environment variable
Igor Pechtchanski wrote: On Thu, 20 Feb 2003, Fred Ma wrote: Hello, I'm using cygwin bash 2.05b-8 (it's actually gnu). I thought that $HOSTNAME was an environment variable. When I run gnu make (I'm pretty sure this is not a make problem), $(HOSTNAME) is empty. It gets fixed if I do export HOSTNAME before running make. Is there a way to check if the export command has been applied to $HOSTNAME? Does the actual transcription of $HOSTNAME's value to the environment happen only once, when export is applied, or is there a continual monitoring an mirroring of changes to $HOSTNAME forever after applying export? Fred Fred, I'm afraid you might be confused about what exporting a variable means. Bash maintains an environment, which contains the values of all the variables it's using. When bash spawns a child, that child inherits those variables from the parent's environment that are exported. Thus, if you export HOSTNAME, the child will get the current value of HOSTNAME. If you then change HOSTNAME in the parent, the child *will not* see the change. However, if you spawn another child, that new child *will* see the new value. BTW, export with no variable name will print out the list of all variables that are exported from the current shell. And, if you want to make sure it's exported, export HOSTNAME can do no harm. But both this and the above are off-topic for the Cygwin list, and could have been found by a simple perusal of man bash. Igor -- http://cs.nyu.edu/~pechtcha/ |\ _,,,---,,_[EMAIL PROTECTED] ZZZzz /,`.-'`'-. ;-;;,_[EMAIL PROTECTED] |,4- ) )-,_. ,\ ( `'-' Igor Pechtchanski '---''(_/--' `-'\_) fL a.k.a JaguaR-R-R-r-r-r-.-.-. Meow! Oh, boy, virtual memory! Now I'm gonna make myself a really *big* RAMdisk! -- /usr/games/fortune Igor, Thanks for the information. The man bash confirms what you said, and what I thought I knew before encountering the problem. What made me uncertain was that things don't always behave the same in the cygwin environment as they do in, say, solaris, and I'm never sure what behaviour might be due to customizations. Another thing that made me unsure was that it seems strange for $HOSTNAME not to be marked export by default, I didn't think that would happen intentionally. Though it appears now that it is that way. I did miss the bit in the man pages about showing all the export variables. My apologies, I should have spent more time reading it more carefully. Fred -- Fred Ma, [EMAIL PROTECTED] Carleton University, Dept. of Electronics 1125 Colonel By Drive, Ottawa, Ontario Canada, K1S 5B6 -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Bug reporting: http://cygwin.com/bugs.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/
Re: Question re. export environment variable
Thanks, Bob. That's the way I expected it to work. I was just unsure of whether there was something cygwin-specific, as it seems strange that something like HOSTNAME is not marked for export at the time that it is set. I'll stick it into ~/.bashrc. Fred -- Fred Ma, [EMAIL PROTECTED] Carleton University, Dept. of Electronics 1125 Colonel By Drive, Ottawa, Ontario Canada, K1S 5B6 Bob McGowan wrote: Fred, perhaps this will help: echo $TEST # Test has no value, hence the blank line. $ TEST=noexport # Set but not exported $ echo $TEST noexport $ env|grep TEST # Nothing found, no output. $ export TEST # Export it. $ env|grep TEST # And now it's found in the environment. TEST=noexport $ TEST=second # Change its value. $ env|grep TEST # Same search as above, but the value is changed. TEST=second Perhaps the easiest way to look at it is to think of exporting as making a type of global variable. Everyone (within certain limits; for the shell, only its children...) will see the exported variable. If the value changes, it changes everywhere. I've quoted everywhere because this only applies to children invoked after the change. So if TEST=second and you run an xterm, the new shell sees TEST=second. Change TEST=third in the first shell, you still have TEST=second in the second shell, since it already got its value for TEST. Start a third shell from the first, it will see TEST=third. And so on. Fred Ma wrote: Hello, I'm using cygwin bash 2.05b-8 (it's actually gnu). I thought that $HOSTNAME was an environment variable. When I run gnu make (I'm pretty sure this is not a make problem), $(HOSTNAME) is empty. It gets fixed if I do export HOSTNAME before running make. Is there a way to check if the export command has been applied to $HOSTNAME? Does the actual transcription of $HOSTNAME's value to the environment happen only once, when export is applied, or is there a continual monitoring an mirroring of changes to $HOSTNAME forever after applying export? -- Bob McGowan Staff Development Engineer VERITAS Software [EMAIL PROTECTED] -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Bug reporting: http://cygwin.com/bugs.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/
Re: Question re. export environment variable
Date: Thu, 20 Feb 2003 12:38:43 -0500 From: Shing-Fat Fred Ma [EMAIL PROTECTED] To: Bob McGowan [EMAIL PROTECTED] CC: [EMAIL PROTECTED] Subject: Re: Question re. export environment variable Thanks, Bob. That's the way I expected it to work. I was just unsure of whether there was something cygwin-specific, as it seems strange that something like HOSTNAME is not marked for export at the time that it is set. I'll stick it into ~/.bashrc. Fred I've always used the set -a shell builtin command in my .bashrc or .kshrc files which then exports all environment variables to all spawned bshells. -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Bug reporting: http://cygwin.com/bugs.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/