'How to add a PWD in to .env

Is there anyway to use pwd or $PWD in .env. Im looking to get the PWD so that I can add it to an PYTHONPATH env.

Thanks,



Solution 1:[1]

.env files in almost every language are hard-coded and not interpreted. @Tyler Stoney's suggestion is a better approach if you need a dynamic env variable available at runtime.

You could write a simple bash function to do this for you dynamically:

function py() {
  PYTHONPATH="$PYTHONPATH:$PWD" python $@
}

Then you could just run py [script.py]

Note: If you try to do this in an alias instead, it will cache the contents of $PWD into the alias so a function is needed instead.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dean Householder