Add derived directory name to runtime LD_LIBRARY_PATH

How can I add a directory to a snap’s runtime LD_LIBRARY_PATH, using a directory that contains the version string, which is derived from the source in the override-build scriptlet? Ideally, I would like to do something like this:

apps:
  octave:
    …
    environment:
      LD_LIBRARY_PATH: "$SNAP/lib/octave/$OCTAVE_VERSION"
…
parts:
  octave:
    …
    override-build: |
      …
      export OCTAVE_VERSION="$(cat version.txt)"
      # some snapcraftctl magic to pass OCTAVE_VERSION to the runtime environment

Note that the version string that I need here is not always identical to the value of SNAP_VERSION, which would otherwise be a perfect solution. I have tried to derive the path using shell expansion on SNAP_VERSION, but that evaluates to an empty string:

    environment:
      LD_LIBRARY_PATH: "$SNAP/lib/octave/${SNAP_VERSION%+*}"

For more context, I am in the process of migrating GNU Octave from core18 to core20. I discovered that with core18, snapcraft had been automatically adding directories that contain shared libraries to the LD_LIBRARY_PATH. Building with core20, the magic is gone, those directories are no longer on LD_LIBRARY_PATH and I am looking for a solution that doesn’t involve hard coding the version.

My work so far is available on the core20 branch here.