There is a RESLOC variable in my .profile file, which changes from time to time. So i wrote a script just take input from user on the new name.
cat tst.sh
echo "Enter the Result Location name where you would like your results to go."
read RESL
perl -pi.bak -e "s/([\s]+)RESLOC=\/result\/([\S]+)/$1 RESLOC=\/result\/${RESL}/g" /user/.profile
cd /user
. /user/.profile
echo "$RESLOC"
The last echo statement gives the output as the value given by user. But when i do echo $RESLOC after the script has been executed in the terminal, it displays the old value.
O/P of the script:
Enter the Result Location name where you would like your results to go.
Release12
/user/Release12
When try to display the RESLOC after the execution is complete.
echo $RESLOC
/user/Release11
The .profile file has been updated with Release12. But it is not sourced properly. Please help.
When you run tst.sh a new shell process is spawned and when it ends your environment will return to the previous instance of the shell, i.e. the one from which you ran tst.sh.
To modify the environment in your current shell, you'll need to source tst.sh;
. tst.sh
This will run tst.sh in your current shell and not spawn a new shell process.