Skip to content
This repository has been archived by the owner on Jan 6, 2021. It is now read-only.

Processing variables on MacOS 10.15.2 only works with single quotes #222

Closed
mansn opened this issue Dec 18, 2019 · 4 comments
Closed

Processing variables on MacOS 10.15.2 only works with single quotes #222

mansn opened this issue Dec 18, 2019 · 4 comments

Comments

@mansn
Copy link

mansn commented Dec 18, 2019

  • cross-env version: 6.0.3
  • node version: 12.8.0
  • npm version: 6.11.3
  • MacOS: 10.15.2 (Catalina)

Put these rules into a package.json file with the cross-env node module installed.

"greet": "npm run greet0 && npm run greet1 && npm run greet2",
"greet0": "cross-env-shell GREETING=Hi NAME=Joe echo unquoted $GREETING $NAME",
"greet1": "cross-env-shell GREETING=Hi NAME=Joe \"echo doubleQuotes $GREETING $NAME\"",
"greet2": "cross-env-shell GREETING=Hi NAME=Joe 'echo singleQuotes $GREETING $NAME'"

npm run greet
See what gets echoed.

This is what I see:

MacOS 10.15.2 Expected(?) Comment
unquoted unquoted Hi Joe
doubleQuotes doubleQuotes Hi Joe I guess this is actually the expected result atm?
singleQuotes Hi Joe singleQuotes Hi Joe

Unfortunately I cannot verify the behavior on Windows.

Problem description:
This problem is pretty much the same as described in #148.
The README.md example shows that you should wrap commands in (double) quotes ("\) if you want environment variable(s) to apply to a series of commands: https://github.com/kentcdodds/cross-env#cross-env-vs-cross-env-shell. But this example doesn't work on MacOS 10.15.2.

Suggested solution:
Unfortunately I haven't had the time to dig into the codebase to propose a solution, other than that "it should work with double qoutes".

@danielo515
Copy link
Contributor

I am also facing this exact problem. You found any workaround?

@mansn
Copy link
Author

mansn commented May 16, 2020

@danielo515 No, not really any workaround. I mean, I use single quotes, but then the npm script won't work on Windows..
Maybe asking Windows users to switch script-shell to powershell could work for them? I.e. by following these guidelines, and then just use single quotes.

@dwiyatci
Copy link

dwiyatci commented Nov 25, 2020

@danielo515 @mansn How bout this pattern below? 👇

"greetDriver": "cross-env GREETING=Hi NAME=Joe npm run greet",
"greet": "npm run greet0 && npm run greet1 && npm run greet2",
"greet0": "cross-env-shell echo unquoted $GREETING $NAME",
"greet1": "cross-env-shell \"echo doubleQuotes $GREETING $NAME\"",
"greet2": "cross-env-shell 'echo singleQuotes $GREETING $NAME'" 

...and then npm run greetDriver or yarn greetDriver should do the job. 😃✨

@kentcdodds
Copy link
Owner

#257

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants