Shell Environment Variables Not Accessible

Version: CommandBox 6.0
Post Upgrade from CommandBox 5.9…

We utilize Shell Environment variables w/in Commandbox but since the upgrade from 5.9 to 6.0 some of the variables, do not appear to within Commandbox. Basic pattern is:

> echo $JAVA_HOME
/opt/homebrew/opt/openjdk/libexec/openjdk.jdk/Contents/Home
> export ai_test=test
> echo $ai_test
test
> box
Commandbox> echo ${JAVA_HOME}
/opt/homebrew/opt/openjdk/libexec/openjdk.jdk/Contents/Home
Commandbox> echo ${ai_test}
Commandbox>

The variable ‘ai_test’ shows as blank. In prior versions it would display ‘test’.

Any ideas or recommendations?

I’m a little confused by these commands as there is no export command in CommandBox. Have you created some special command aliases?

Type-o… Meant

> echo $JAVA_HOME
/opt/homebrew/opt/openjdk/libexec/openjdk.jdk/Contents/Home
> export ai_test=test
> echo $ai_test
test
> box
Commandbox> echo ${JAVA_HOME}
/opt/homebrew/opt/openjdk/libexec/openjdk.jdk/Contents/Home
Commandbox> echo ${ai_test}
Commandbox>

To add some additional context, after further testing many other Shell Environment variables report blank as well. Here are a few examples

Commandbox> echo ${HOMEBREW_CELLAR}
Commandbox> echo ${VENDOR}

but these return work

Commandbox> echo ${HOME}
/Users/Shared/computername
Commandbox> echo ${PATH}
/usr/local/bin:/Users/Shared/.... 

Final info.
Chip: Apple M1 Pro
Running Sonoma 14.4

Let me know if there is any additional information I can provide that might help.

Thanks!

If you run printenv do those variables appear as non empty? If not, then a recent OS update to the shell might have changed something. If so, then you may need to add exports to your shell configuration file.

Note though, that the openjdk homebrew install is Java 21, which can cause some issues with older engines and some code bases which use Java heavily.

CommandBox hasn’t really changed anything in regards to how it accesses env var. It just gets them right from java.lang.System. I don’t have a Mac, but everything seems to work just fine on my Windows 11 machine.

C:\Users\brad>set brad=wood

C:\Users\brad>box echo ${brad}
wood

HOMEBREW_CELLAR and VENDOR appear to be HomeBrew specific env vars, and perhaps Homebrew itself stopped populating.

A couple things to try. Look and see exactly what Java is reporting as the env vars like so

CommandBox> repl server.system.environment

which will output the JSON serialized struct from Lucee’s server scope.

Or, if you want to get it straight from the horse’s mouth…

repl createObject('java','java.lang.System').getEnv()

which will show you exactly what Java is seeing.

You can also ask the native shell what it sees:

CommandBox> !echo %brad%
wood

That’s for CMD, again adjust for *nix. You should prolly be able to run

CommandBox> !printenv

as Jon suggested.

Thank you both for the information. I was able to track down a way to resolve by leveraging ‘sudo -E’ when starting box.

> sudo -E box
Commandbox> !printenv
MANPATH=/opt/homebrew/share/man::
SHELL=/bin/zsh
... {rest of environment variables}
Commandbox>