Closed ComLock closed 5 years ago
~/.bash_profile
export DOT_ENONIC="$HOME/.enonic"
export XP_VERSION='7.0.0'
export XP_INSTALL="$DOT_ENONIC/distributions/enonic-xp-mac-sdk-$XP_VERSION"
export JAVA_HOME="$XP_INSTALL/jdk"
export XP_SANDBOX='whatever'
export XP_HOME="$DOT_ENONIC/sandboxes/$XP_SANDBOX/home"
It looks like you don't need to use the source command.
What you need is to return a string, which contains the bash commands that is needed to setup the environment. Then you have to eval that string in the current terminal.
ASFAIK this can be done in bash by using the dollar paranteses syntax:
$(echo "export XP_HOME='/tmp'"); echo $XP_HOME
https://stackoverflow.com/questions/39110485/difference-between-and-in-bash
Here's how to set two environment variables without error messages:
$(echo "set ONE='1';set TWO='2'"); echo $ONE; echo $TWO
NOPE SORRY I NEED TO TEST MORE, IT DOESN'T WORK
To check whether a variable is marked as exported in the current shell use
compgen -e -X '!ONE'
So the final command would look like this:
$(enonic project env)
eval $(echo "XP_HOME=/x;JAVA_HOME=/j;echo XP_HOME=\$XP_HOME; echo JAVA_HOME=\$JAVA_HOME")
Backticks are shorter and perhaps supported by more terminals, but then again harder to write:
eval `echo "XP_HOME=/x;JAVA_HOME=/j;echo XP_HOME=$XP_HOME; echo JAVA_HOME=$JAVA_HOME"`
You can also use redirection like this:
eval <<< echo 'XP_HOME=/x;JAVA_HOME=/j;echo XP_HOME=$XP_HOME; echo JAVA_HOME=$JAVA_HOME'
eval export `echo 'XP_HOME=/x;JAVA_HOME=/j;echo XP_HOME=$XP_HOME; echo JAVA_HOME=$JAVA_HOME'`
I think
eval <<< enonic project env
Is the best, because it's short and does not use backticks
Another option, but with backticks
export `echo -e "XP_HOME=/x\nJAVA_HOME=/j"`
List all exported vars:
export -p
enonic project shell
starts a new terminal, typically a completely other terminal than I use.I would be nice to have a
enonic project env
which exports the required variables so one can runsource enonic project env
to change the current environment.https://bash.cyberciti.biz/guide/Source_command
Other possible names: