From 7d4b681fe1e2ba575bbfc09ca2b7631724fe649b Mon Sep 17 00:00:00 2001 From: Sergio Costas Rodriguez Date: Fri, 12 Jun 2026 10:35:47 +0200 Subject: [PATCH 1/3] docs: add documentation for new BASH syntax Since snapd 2.77 onward, support for BASH syntax ${VAR:+value} and ${VAR:-default} is available for environment variable values. This patch adds it to the documentation, to ensure that it will be explained in the docs web pages. --- snapcraft/models/project.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/snapcraft/models/project.py b/snapcraft/models/project.py index c572896d45..91e1b1fd4c 100644 --- a/snapcraft/models/project.py +++ b/snapcraft/models/project.py @@ -1858,6 +1858,11 @@ class Project(models.Project): Environment variables are set at runtime for all apps. To set an environment variable for a particular app, use the ``environment`` key for that ``app`` entry. + + From snapd 2.77 onward, support for BASH syntax ``${VAR:+value}`` and + ``${VAR:-default}`` is available for environment variable values. Also + ``${VAR:+$OTHER_VAR}`` and ``${VAR:-$OTHER_VAR}`` are supported, but internal + braces are not supported (so , for example, ``${VAR:+${OTHER_VAR}}`` won't work). """ build_packages: Grammar[list[str]] | None = pydantic.Field( From 767d5309a17a73d718344ba50bff1c4f54ca23c6 Mon Sep 17 00:00:00 2001 From: Sergio Costas Rodriguez Date: Fri, 17 Jul 2026 13:54:07 +0200 Subject: [PATCH 2/3] Add suggestion --- snapcraft/models/project.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/snapcraft/models/project.py b/snapcraft/models/project.py index 91e1b1fd4c..2216c6e689 100644 --- a/snapcraft/models/project.py +++ b/snapcraft/models/project.py @@ -1863,6 +1863,9 @@ class Project(models.Project): ``${VAR:-default}`` is available for environment variable values. Also ``${VAR:+$OTHER_VAR}`` and ``${VAR:-$OTHER_VAR}`` are supported, but internal braces are not supported (so , for example, ``${VAR:+${OTHER_VAR}}`` won't work). + + To ensure this feature is available, use the ``assumes`` key to require a + minimum version of snapd, for example ``assumes: [snapd2.77]``. """ build_packages: Grammar[list[str]] | None = pydantic.Field( From f5c94fce58383c191b6965dd9d278cdc1dc2d059 Mon Sep 17 00:00:00 2001 From: Sergio Costas Date: Thu, 23 Jul 2026 09:09:15 +0200 Subject: [PATCH 3/3] Update snapcraft/models/project.py Co-authored-by: Michael DuBelko Signed-off-by: Sergio Costas --- snapcraft/models/project.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/snapcraft/models/project.py b/snapcraft/models/project.py index 2216c6e689..7d8afe6af8 100644 --- a/snapcraft/models/project.py +++ b/snapcraft/models/project.py @@ -1859,10 +1859,14 @@ class Project(models.Project): environment variable for a particular app, use the ``environment`` key for that ``app`` entry. - From snapd 2.77 onward, support for BASH syntax ``${VAR:+value}`` and - ``${VAR:-default}`` is available for environment variable values. Also - ``${VAR:+$OTHER_VAR}`` and ``${VAR:-$OTHER_VAR}`` are supported, but internal - braces are not supported (so , for example, ``${VAR:+${OTHER_VAR}}`` won't work). + With SnapD 2.77 and higher, this key supports Bash parameter expansions: + + - Override the current value with ``${VAR:+override}`` + - Fall back to a value with ``${VAR:-fallback}`` + - Copy another variable's value with ``${VAR:+$OTHER_VAR}`` + - Fall back to another variable's value with ``${VAR:-$OTHER_VAR}`` + + Nested braces such as ``${VAR:+${OTHER_VAR}}`` aren't supported. To ensure this feature is available, use the ``assumes`` key to require a minimum version of snapd, for example ``assumes: [snapd2.77]``.