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.

Variable substitution with environment - allow for fallback to default

See original GitHub issue

When doing variable substitution with environment (at debugging launch, but could be useful for tasks too - ${env:Name}), I would like to provide a fallback (default) when the environment variable is not set.

As an example, see the variable substitution scheme for Docker Compose: https://docs.docker.com/compose/compose-file/#variable-substitution

  • ${VARIABLE:-default} evaluates to default if VARIABLE is unset or empty in the environment.
  • ${VARIABLE-default} evaluates to default only if VARIABLE is unset in the environment.

The syntax for VS Code could be ${env:Name:-default} and ${env:Name-default} with the same logic.

VS Code version 1.42.1

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:35
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
alexr00commented, Apr 27, 2020

Instead of using env you could write an extension that provides a command and use command input variables

0reactions
flying-sheepcommented, Apr 26, 2020

Any way to circumvent this for now? I want to do use XDG basedir spec and prepend something to XDG_DATA_DIRS.

To this end I need to retrieve the value of XDG_DATA_DIRS if it’s set and use a default when it isn’t set, which would look like this:

"env": {
    "XDG_DATA_DIRS": "${workspaceFolder}/something:${env:XDG_DATA_DIRS-/usr/local/share:/usr/share}"
}

There seems to be no way to currently do this in a launch configuration, and falling back to the empty string will break every GUI application launched with that env value set.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fallback for environment variables with docker-compose
The supported forms are ${FOO-default} (fall back if FOO is unset) and ${FOO:-default} (fall back if FOO is unset or empty). Save this...
Read more >
how do I reference a variable in fish shell with a default fallback
If you really want the ability to substitute a default in-line, you can do it in a function using indirection, and then call...
Read more >
Variable substitutions - Octopus Deploy
Variable substitutions are a flexible way to adjust configuration based on your variables and the context of your deployment.
Read more >
Allow default value for variables (&7437) · Epics · GitLab.org
Which means that if the fallback is not of type string CI will use an environment variable. This can be stacked endlessly. 9....
Read more >
10.2. Parameter Substitution
The default parameter construct finds use in providing "missing" command-line ... #!/bin/bash # Check some of the system's environmental variables.
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