zx
zx copied to clipboard
Setting env variable is not working for me using `within`
Hello,
I am implementing some nice scripts using zx but one feature is not working at all in my case, setting an environment variable (a java classpath, in my case, which can be huge) and using it in further calls. Note: doing some else like cd("..") is working !
Expected Behavior
$ echo $FOO
bar
Actual Behavior
$ echo $FOO
Steps to Reproduce the Problem
I am running:
await within(async () => {
$.env.FOO = 'bar';
await $`echo $FOO`;
});
or
await within(async () => {
process.env.FOO = 'bar';
await $`echo $FOO`;
});
or even
await within(async () => {
await $`export FOO=bar`;
await $`echo $FOO`;
});
Specifications
- Version: "zx": "7.2.3"
- Platform: Windows 11 + WSL
I only can find information that it should be working, and I do not know how to debug further to understand what is happening.
I had the same problem.
It works according to specs, you just need to replace the whole $.env object like that:
$.env = { ...process.env, FOO: "BAR" };