6

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?

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.