0

I exported variable in local environment, and need to pass that variable into bash script, which in turn will need to run python script using that env.

#!/usr/bin/env bash
export API_TOKEN=836176e9b6ce
sudo python script.py --pretty

Right now I am getting following:

Could not find values for Program api_token.
They must be specified via either ini file, command line argument (--api-token),
or environment variables (API_TOKEN)

Is it possible to achieve?

2
  • It's hard to answer this without seeing the script.py code. Is the message you posted coming from bash or python? Are you reading API_TOKEN in the python code? A lot more information is needed to answer this. Commented Nov 7, 2017 at 19:42
  • @bluegreen - yes, it was reading token in the python code - and the message was coming from python script - solution and flag suggested by janos fixed the issue Commented Nov 7, 2017 at 19:46

1 Answer 1

3

The environment you set in the script is not passed through to the command executed by sudo. To preserve environment variables, use the -E flag:

#!/usr/bin/env bash
export API_TOKEN=836176e9b6ce
sudo -E python script.py --pretty
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.