Variable substitution with environment - allow for fallback to default
See original GitHub issueWhen 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 ifVARIABLE
is unset or empty in the environment.${VARIABLE-default}
evaluates to default only ifVARIABLE
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:
- Created 4 years ago
- Reactions:35
- Comments:5 (1 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Instead of using
env
you could write an extension that provides a command and use command input variablesAny 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:
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.