export variables
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi friends...
I have a trouble when try to export variables... I write a script like this:
- -------------- test.sh ------------------
export MY_VAR="SOME_VALUE"
echo "$MY_VAR"
- -------------- test.sh ------------------
later: chmod +x test.sh then run this script: ./test.sh ... everything looks
OK :)
but when try to use this variable in my environment I can't do, if write
"env" the nev variable MY_VAR doesn't appear ... I think that there are some protection about export variables, but how do I can export variables?
I'm using red hat 7.3
thanks
- --
Linux User Registered #232544
my GnuPG-key at www.keyserver.net
--- rm -rf /bin/laden ---
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
iD8DBQE+MO+xs4dF9gl05swRApKYAJ0TmE/LvroRvx9BFMgYxZkHP9vNnACeKYkH PbQvNbrsquCZ0dSrEJXxsC4=
=EQRI
-----END PGP SIGNATURE-----
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs
use the ($) just in front of the variable when testing it in an if statement or trying to echo its value.
Signature · 7 lines
Jude <dashielljt(at)gmpexpress-dot-net> - To unsubscribe from this list: send the line "unsubscribe linux-newbie" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.linux-learn.org/faqs
Quoted 9 lines
- --------------
test.sh------------------ export MY_VAR="SOME_VALUE"
echo "$MY_VAR"
- --------------test.sh------------------
later: chmod +xtest.shthen run this script: ./test.shbut when try to use this variable in my environment I can't do, if write
"env" the nev variableMY_VARdoesn't appear ... I think that there are some protection about export variables, but how do I can export variables?
The environment of a process cannot easily be changed from outside that process once the process has started running. This means that exporting a variable does not do the obvious thing: if you run a shell script, which tries to export a variable, then that variable will only be exported to processes which are spawned by that shell script. In particular, if test.sh contains
export WIDGET=wobble
then running test.sh will have absolutely no effect on the environment of the shell which invoked it.
If you need to change a running shell's environment through a script, then you need to get that shell to source rather the script rather than to execute it. To do this, go
$ . ./test.sh
This causes the shell to run test.sh as if it had been typed in at the command line, rather than spawning an entirely independent shell and running test.sh through that.
Steven Smith,
[email protected].