script executed inside another script dont make changes
Hello,
I have a script B that is executed inside a main script A. The script B make some changes in the environment variables like JAVA_HOME. When I execute script B in command line everything's fine and the variables are updated. When I execute script A, apparently the script B outputs the right things but the variables are not updated at the end. I've tried all the ways: ./scriptB.sh . scriptB.sh path/to/script/scriptB please help me!!!!! |
If script B is called by script A, then you need to source script B for the variables in A to be effected.
|
ok the script B only works if it is entered like this in the command line:
. scriptB.sh I almost reach the end of the internet with this problem... I realy dont no why it as to be like that. But i want to automize the process and that's why I want to execute script B inside script A.... |
The point is that each time you start a new program, normally it starts a new sub-shell to run it in.
Shell env vars can only be exported (passed) downwards, not up, so when the sub-shell exits (completes), it's entire env, inc (sub-shell) vars disappears. However, if you source scriptB.sh or . scriptB.sh (both do the same thing), then the scriptB.sh is run as if you had added the code directly into the caller prog (scriptA.sh), so created vars are retained in the scriptA.sh env. Read this: http://www.tldp.org/LDP/abs/html/subshells.html HTH |
ok thanks that's great, thank you for your time.
|
All times are GMT -5. The time now is 03:01 PM. |