Skip to content

docs: Add documentation for new BASH syntax - #6290

Open
sergio-costas wants to merge 3 commits into
canonical:mainfrom
sergio-costas:add-documentation-for-new-envvar-bash-syntax
Open

docs: Add documentation for new BASH syntax#6290
sergio-costas wants to merge 3 commits into
canonical:mainfrom
sergio-costas:add-documentation-for-new-envvar-bash-syntax

Conversation

@sergio-costas

Copy link
Copy Markdown
Contributor

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.


  • I've followed the contribution guidelines.
  • I've signed the CLA.
  • I've successfully run make lint && make test.
  • I've added or updated any relevant documentation.
  • In documents I changed, I added a meta description if one was missing.
  • I've updated the relevant release notes.

@sergio-costas
sergio-costas force-pushed the add-documentation-for-new-envvar-bash-syntax branch from 95d6ad7 to f72d662 Compare June 12, 2026 08:45
@sergio-costas sergio-costas changed the title project: Add documentation for new BASH syntax docs: Add documentation for new BASH syntax Jun 12, 2026
@sergio-costas
sergio-costas force-pushed the add-documentation-for-new-envvar-bash-syntax branch from f72d662 to c540bd6 Compare June 12, 2026 08:52
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.
@sergio-costas
sergio-costas force-pushed the add-documentation-for-new-envvar-bash-syntax branch from c540bd6 to 7d4b681 Compare June 12, 2026 08:53

@mr-cal mr-cal left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @sergio-costas !

I've put my suggestion in and am also requesting a review from @canonical/starcraft-authors.

Comment thread snapcraft/models/project.py Outdated
@mr-cal
mr-cal requested a review from a team July 17, 2026 11:35
Copilot AI review requested due to automatic review settings July 17, 2026 11:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds documentation to the environment field schema/docs explaining that snapd (>= 2.77) supports Bash parameter expansion in environment variable values, and how to gate usage via assumes.

Changes:

  • Document support for ${VAR:+value} and ${VAR:-default} in environment variable values (snapd 2.77+).
  • Clarify limitations (no nested parameter expansion) and provide examples.
  • Recommend using assumes: [snapd2.77] to require the needed snapd feature level.

Comment thread snapcraft/models/project.py Outdated
@sergio-costas
sergio-costas force-pushed the add-documentation-for-new-envvar-bash-syntax branch from 8537692 to 767d530 Compare July 17, 2026 11:54

@medubelko medubelko left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @sergio-costas!

I went deep in trying to make this easier for users to parse. Let me know what you think!

Comment thread snapcraft/models/project.py Outdated
Comment on lines +1862 to +1865
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).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's my attempt to make it a little more digestible:

Suggested change
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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks much better, but I still see it a little bit complex... Maybe adding some examples would help?

Comment on lines +1867 to +1868
To ensure this feature is available, use the ``assumes`` key to require a
minimum version of snapd, for example ``assumes: [snapd2.77]``.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
To ensure this feature is available, use the ``assumes`` key to require a
minimum version of snapd, for example ``assumes: [snapd2.77]``.
For parameter expansion, the ``assumes`` key must be set to a
minimum version of SnapD, such as ``[snapd2.77]``.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe... "If parameter expansion is used, it is paramount to set the assumes key to version 2.77 or later (such as assumes: [snapd2.77])".

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the word "paramount" feels a little too glittery. I don't like the "such as" in Michael's suggestion either, because it feels a suggestion that you can pin it to whatever version you want, so long as you're pinning it at all.

How about:

Suggested change
To ensure this feature is available, use the ``assumes`` key to require a
minimum version of snapd, for example ``assumes: [snapd2.77]``.
Since this feature requires a minimum version of SnapD, use the ``assumes`` key to
constrain your snap to a supported SnapD version with ``assumes: [snapd2.77]``.

Co-authored-by: Michael DuBelko <michael.dubelko@gmail.com>
Signed-off-by: Sergio Costas <sergio.costas@canonical.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants