From 206b0895fd071693c8688864d3f26d2a0b3f204c Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Sun, 22 Dec 2024 14:02:11 -0800 Subject: [PATCH] Document using `||` to provide default for empty environment variable (#2545) --- README.md | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 99251e8fa9..a8c1559817 100644 --- a/README.md +++ b/README.md @@ -1645,11 +1645,11 @@ olleh := shell('import sys; print(sys.argv[2][::-1])', 'hello') #### Environment Variables -- `env_var(key)` — Retrieves the environment variable with name `key`, aborting +- `env(key)` — Retrieves the environment variable with name `key`, aborting if it is not present. ```just -home_dir := env_var('HOME') +home_dir := env('HOME') test: echo "{{home_dir}}" @@ -1665,6 +1665,15 @@ $ just - `env(key)`1.15.0 — Alias for `env_var(key)`. - `env(key, default)`1.15.0 — Alias for `env_var_or_default(key, default)`. +A default can be substituted for an empty environment variable value with the +`||` operator, currently unstable: + +```just +set unstable + +foo := env('FOO') || 'DEFAULT_VALUE' +``` + #### Invocation Information - `is_dependency()` - Returns the string `true` if the current recipe is being