[SOLVED] source command doesn/t work when used inside shell script
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
source command doesn/t work when used inside shell script
Hi Everyone,
I am using an installer which is adding entry of environment variable in bash_profile file, when i am starting jetty server, it was unable to find that entry..when i run source ~/.bash_profile it rerlaods the bash profle and server starts succesfully without any issues..The problem is customer is not going to start a new session nor he is going to manually refresh the bash_profile.I tried to add the "source ~/.bash_profile" command inside a shell script and i called that shell script when i invoke the startup file of jetty server but it also doesn't work..Is there any other way we can reload the bash profile of current session?Any information you can provide me would be greatly appreciated.
Thanks,
Shaleen
Last edited by shaleenmadlapure; 06-22-2016 at 05:28 AM.
the problem is that you gave almost no information about the situation. All we know is: you have a bash_profile file and it was sourced. But how did you start your server, how did you invoke the startup file of jetty server, what kind of shell script is used to source ~/.bash_profile ?
Probably you missed you cannot change the environment of a running process by sourcing anything in a terminal. But it is only a wild guess.
I am using an installer which is adding entry of environment variable in bash_profile file, when i am starting jetty server, it was unable to find that entry..when i run source ~/.bash_profile it rerlaods the bash profle and server starts succesfully without any issues..The problem is customer is not going to start a new session nor he is going to manually refresh the bash_profile.I tried to add the "source ~/.bash_profile" command inside a shell script and i called that shell script when i invoke the startup file of jetty server but it also doesn't work..Is there any other way we can reload the bash profile of current session?Any information you can provide me would be greatly appreciated.
Thanks,
Shaleen
Interesting.
Adding a source file to the jetty startup script? Yes, NO. Not gonna work.
1)I have created startUp script startJetty.sh, whose contents are below
#!/bin/sh
sh refreshBashProfile.sh
java -Xms1024M -Xmx1024M -Djavax.xml.soap.MessageFactory=com.sun.xml.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl -Dorg.eclipse.jetty.annotations.maxWait=1200 -Djetty.http.port=8080 -DaligneServerHost=10.253.80.38 -DaligneServerPort=1299 -Dtrmapp.properties=/home/donotlogoff/temp/jetty-distribution-9.3.5.v20151012/TRMClient.properties -Dwebserver.url=http://ap-pun-ws6801:8080/IdPRI-4.3.0 -jar start.jar
2)In the same directory I have created another shell file refreshBashProfile.sh which contains below command
#!/bin/sh
echo bash_profile refreshed succesfully
source ~/.bash_profile
3)Now when i run the startJetty.sh, echo statement is also printing properly but bash_profile is not refreshed.and server started with errors.if i manually refresh the bas_profile and starts server then server starts succesfully.
sh refreshBashProfile.sh will fork a new shell and sourcing will be executed in the new shell. This new shell is actually finished just after the source command and dropped.
Sourcing in the child shell will not affect the parent in any way. That is not possible.
instead of sh refreshBashProfile.sh you need to execute the source command directly in that startJetty.sh.
sh refreshBashProfile.sh will fork a new shell and sourcing will be executed in the new shell. This new shell is actually finished just after the source command and dropped.
Sourcing in the child shell will not affect the parent in any way. That is not possible.
instead of sh refreshBashProfile.sh you need to execute the source command directly in that startJetty.sh.
I tried this its not working, what i did is just removed the path of java from bash_profile and then ran jetty.sh and still server started.
it means its not reloading the bash_profile.
when i opened the new session then its giving error java not found
What user is used when modifying the ~bash_profile, and what user is used when starting the server?
Second, how is the startup script being invoked when it doesn't work?
Most services are not started by a user, but by the system.
1)Its the same user through which i have loggged in putty. its not an root user but customized user and same user is used in modification and starting server.
2)I am using command sh startJetty.sh to start the server.Even if you remove the java path and run the shell its taking the old path because environment property is not refreshed yet ..if you close the session then i am unable to run the startup script because now the bash_profile is reloaded.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.