In a sh script another sh script is started with
su -l <user> -c /path/to/script.sh. As far as I understood
script.sh will be run in a non-interactive shell. The official documentation tries to explain how to set variables in such a non-interactive shell, namely pass them in
BASH_ENV[http://www.gnu.org/software/bash/manual/html_node/Bash-Startup-Files.html ]. This is obviously an insufficient explanation for a beginner and there's no (real) example (didn't find one in $SEARCH_ENGINE neither).
if [ -n "$BASH_ENV" ]; then . "$BASH_ENV"; fi
can mean mean a lot . Can someone please give an example of an environment variable passed to a non-interactive shell.
Just to make sure: the difference between login and non-login as well as interactive and non-interactive are clear for me (https://superuser.com/questions/636219/where-should-i-export-an-environment-variable-so-that-all-combinations-of-bash-d or referenced link if anyone is interested).
BASH_ENV="\\$PATH=$PATH\\n\\$JAVA_HOME=$JAVA_HOME" su -l artifactory -c echo $JAVA_HOME
BASH_ENV="\$PATH=$PATH\n\$JAVA_HOME=$JAVA_HOME" su -l artifactory -c echo $JAVA_HOME
su -l artifactory -c echo $JAVA_HOME