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

Get en variable value from inline command? #55

Closed
sinedied opened this issue Feb 8, 2017 · 3 comments
Closed

Get en variable value from inline command? #55

sinedied opened this issue Feb 8, 2017 · 3 comments

Comments

@sinedied
Copy link

sinedied commented Feb 8, 2017

Can we assign env variables from command results?

In my package.json I have:

    "build": "cross-env PKG_VERSION=$(npm run version) ng build",
    "version": "node -p -e \"require('./package.json').version\""

Does this work on windows? (I only have a mac at hand for now)
Thanks

@kentcdodds
Copy link
Owner

I'm not sure whether that works properly on windows. But it's definitely outside of the scope of cross-env because the way it works on mac is what is inside $() will run before the rest of the script is run (so if you were to put a console.log in cross-env, you wouldn't see $(npm run version) at all, but instead you'd see the evaluated version).

Incidentally, for this specific scenario, you might consider using the environment variable npm_package_version which is set for you automatically when running npm scripts. (Learn more).

Good luck!

@sinedied
Copy link
Author

sinedied commented Feb 8, 2017

Thanks for the tip with npm_package_version, but with other use cases is there a way to get value from another command execution?

@kentcdodds
Copy link
Owner

I'm not sure about that. I don't know how you'd do $(command) on Windows. But in any case, that's definitely not in scope for cross-env I'm afraid. Best of luck to you!

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

2 participants