speeves@hk:~/scripts$ ./x.sh
speeves@hk:~/scripts$ echo $authtoken
speeves@hk:~/scripts$ . ./x.sh
speeves@hk:~/scripts$ echo $authtoken
hello world
x.sh:
export authtoken="hello world"
With a little side of applesauce...
speeves@hk:~/scripts$ ./x.sh
speeves@hk:~/scripts$ echo $authtoken
speeves@hk:~/scripts$ . ./x.sh
speeves@hk:~/scripts$ echo $authtoken
hello world
export authtoken="hello world"
©2006 Shannon Eric Peevey
4 comments:
No important information.
good to know. thanks for sharing :)
other ways to tinker with the parents environment are quite complicated. this method doesnt actually changes the _parent_, it gets executed INSIDE the parent... so there is basically no child or parent.
(is that correct?)
According to the BASH Prompt HOWTO, http://tldp.org/HOWTO/Bash-Prompt-HOWTO/x237.html
sourcing a file acts as if the command were printed on the command line. My expectation would be that an export, (which is used to make variables from children available to parents), would also work in this case. It seems pretty esoteric, but it would be interesting to hear from a real BASH guru that could explain what is happening here :)
export is used to make variables from parent known to its children, not the other way around.
And sourcing the file by '.' does not spawn a child shell but the scripts gets executed in the current shell.
Post a Comment