Variables being substituted too early in Greet example.
thomasmichaelwallace opened this issue · comments
This might be user error, but:
cross-env
version: 5.1.4node
version: 6.10.3 and 8.6.0npm
version: 3.10.10yarn
version: 1.5.1mac os
version: 10.13.3
What you did:
Tried the example 'greet':
"scripts": {
"greet": "cross-env-shell GREETING=Hi NAME=Joe \"echo $GREETING && echo $NAME\""
}
What happened:
both yarn greet
and npm run greet
outputs two blank lines, instead of the expected Hi/nJoe
.
Problem description:
By adding in some logging I can see that ./node_modules/.bin/cross-env-shell
invokes crossEnv with [ 'GREETING=Hi', 'NAME=Joe', 'echo && echo ' ]
.
Suggested solution:
Mucking about I found that switching "
with '
works fine:
"scripts": {
"greet": "cross-env-shell GREETING=Hi NAME=Joe 'echo $GREETING && echo $NAME'"
}
I'm happy to do a PR, but I thought I'd raise an issue first; just in case this solution doesn't work cross-platform.
Thanks @thomasmichaelwallace.
Yeah, I'm pretty sure using '
wont work on windows. We'll have to come up with something else.
I think you'd need some sort of escape syntax- without it linux-esq environments will expand/resolve the variables before cross-env-shell gets to see them.
Either that or maybe we should have a better (more practical) example and make sure we're not doing extra work for something nobody's ever going to use.
Good point- I guess it only really catches you out when you're using an environment variable as an argument across multiple commands; but I expect you can workaround that limitation by having a wrapper-script.
Yep. I'm really hesitant to change this project. It has had too many changes and become way more complicated than it was supposed to. So I'll go ahead and close this and we can work on it again if someone ever has a real use case.