I have a package.json that has the following script:
"scripts": {
"config": ". ./setup.sh"
},
The setup.sh file prompts the user for an API token,
read -p "Enter API Authorization Token: " val
export API_AUTH_TOKEN=$val
and an environment via a PS3 menu. Ex: entering 1 should export DEFAULT_ENV='http://localhost:8000'.
And when I run this setup.sh via the terminal(. ./setup.sh), it works great. It's only when I run "npm run config", where it doesn't actually export those values, although it acts like it did. I'm under the impression this is related to this script being a process within the other process, and so, not affecting the global environment. How do I make it so that it does?
This is because export only works in child processes and itself.
You can edit your file, adding the line to see it:
read -p "Enter API Authorization Token: " val
export API_AUTH_TOKEN=$val
echo $API_AUTH_TOEKEN
In fact it never affects the parent process (like the shell window)
To affect the global, you should save the variable in files like .bashrc
and source .bashrc
to make it into effect.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With