question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Specify syntax of using existing environment variables in .env file

See original GitHub issue

Issue Type: Bug

I’ve been looking at the docs and I think there needs to be some clarification, or there is a bug:

According to the docs, variables in .env file can be substituted by usage of <VARIABLE>=...${EXISTING_VARIABLE}... syntax. As I have discovered, this works for variables defined previously in the .env file, but not for system environment variables. System env variables need following syntax (tested): <VARIABLE>=...${env:EXISTING_SYSTEM_ENV_VARIABLE}...

Can you please specify how it should be, and update the docs?

Extension version: 2019.11.50794 VS Code version: Code 1.41.0 (9579eda04fdb3a9bba2750f15193e5fafe16b959, 2019-12-11T18:37:42.077Z) OS version: Windows_NT x64 10.0.18362

System Info
Item Value
CPUs Intel® Core™ i5-4570 CPU @ 3.20GHz (4 x 3193)
GPU Status 2d_canvas: enabled
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
oop_rasterization: disabled_off
protected_video_decode: unavailable_off
rasterization: enabled
skia_renderer: disabled_off
surface_control: disabled_off
surface_synchronization: enabled_on
video_decode: enabled
viz_display_compositor: enabled_on
viz_hit_test_surface_layer: disabled_off
webgl: enabled
webgl2: enabled
Load (avg) undefined
Memory (System) 15.89GB (6.49GB free)
Process Argv L:\commonPyLibs\commonPyLibsPresentation.code-workspace
Screen Reader no
VM 0%

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
DonJayamannecommented, Feb 1, 2020

ple windows batch script use this approach

That’s a Windows batch file scrip, not a .env file. I’m referring to just a regular .env file.

To my knowledge .env files with support for nested variables doesn’t exist in the most popular php, python and node packages (packages that support loading variables from .env files), including bash script with support for auto loading such variables. Hence my assumption about these being non-standard in .env files.

Please understand I’m not saying we should remove it. It’s a feature that exists in the extension today, and won’t be removed. I was merely expressing my opinion about this feature.

1reaction
karthiknadigcommented, Jan 29, 2020

Looks like this is a bug in the extension.

For repro this should work:

TESTVAR1=${PROCESSOR_IDENTIFIER}

ENVVAR=somevalue
TESTVAR2=${ENVVAR}

test_env.py:

import os

for i in range(1,3):
    print(f"TESTVAR{i}: " + os.getenv(f"TESTVAR{i}"))

launch.json:

{
    "name": "Python file",
    "type": "python",
    "request": "launch",
    "program": "${workspaceFolder}/test_env.py",
    "console": "integratedTerminal",
    "envFile": "${workspaceFolder}/.env"
}

expected output:

TESTVAR1: Intel64 Family 6 Model 61 Stepping 4, GenuineIntel
TESTVAR2: somevalue

actual output

TESTVAR1:
TESTVAR2: somevalue
Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Use Environment Files with env-cmd | DigitalOcean
Learn how to add handle environment variables with the env-cmd package.
Read more >
Environment variables in Compose | Docker Documentation
You can set default values for environment variables using a .env file, ... Similarly, the following syntax allows you to specify mandatory variables:....
Read more >
Set environment variables from file of key/value pairs
This solves the potential problem when going from project to project. env $(cat .env | xargs) rails. I've tested this with bash 3.2....
Read more >
What is .env ? How to Set up and run a .env file in Node?
Environment variables must be used to configure any variables or configuration details that may differ between environments.
Read more >
Working with Environment Variables in Python - Twilio
But if you cannot commit the .env file, how do you tell users of the project which variables need to be set? For...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found