After poking around in dash source I found that "$HOME/.profile" has been hardcoded. So the change needs be made in the shell to make ".profile" safe.
Also I found a way to keep the variables from subshell
### test.sh ###
ERRCODE=0
TEST=""
VARS=$(set -e; . $HOME/script.sh 1>/dev/null; set) || ERRCODE="$?"
if [ $ERRCODE==0 ]
then
eval $VARS
fi
echo "ERRCODE =" $ERRCODE
echo " TEST =" $TEST
### script.sh ###
TEST="something"
function AddPath { echo "err" }
######
This also has one nice thing that when the script fails the environment stays unchanged. Also there may be some variables that shouldn't be taken from the subshell, but I have no idea which.
Right forgot about the variables.
After poking around in dash source I found that "$HOME/.profile" has been hardcoded. So the change needs be made in the shell to make ".profile" safe.
Also I found a way to keep the variables from subshell
### test.sh ###
ERRCODE=0
TEST=""
VARS=$(set -e; . $HOME/script.sh 1>/dev/null; set) || ERRCODE="$?"
if [ $ERRCODE==0 ]
then
eval $VARS
fi
echo "ERRCODE =" $ERRCODE
echo " TEST =" $TEST
### script.sh ###
TEST="something"
function AddPath { echo "err" }
######
This also has one nice thing that when the script fails the environment stays unchanged. Also there may be some variables that shouldn't be taken from the subshell, but I have no idea which.