Create a snap with shell script which calls a binary

So creating a first snap package.
my pipeline produces two artifacts a binary and shell script which has hard coded path to the binary. I would like to create a snap which installs both and changes shell script to call binary contained in snap package.

Any pointers please ?

1 Like
  1. Use relative path to binary
  2. Use the $SNAP environment variable

Thanks, so i do need to change shell script ?

i.e. in shellscript
mono path_to_binary “$1”
change it to
mono $SNAP/path_to_binary “$1”


plugin: nil
source: .
artifacts/lib/my/my.exe: usr/local/lib/my.exe
command: myexe

Likely yes, consider using $@ to replace $1

well the shell script hangs no o/p if i run it after snap is installed.

is i run shell it works

m@mtp ~/w/fsx> snap run --shell fsx.fsx
m@mtp:~/work/fsx$ cd $SNAP
m@mtp:/snap/fsx/x1$ bin/fsx
At least one argument expected
m@mtp:/snap/fsx/x1$ bin/fsx -d
executing mono

This has been confusing. Help Please


Really stumped here. will be grateful for any pointers

binary and shell works out of snap , inside snap shell but not when the snap is installed. doing a strace just goes on without any helpful messages

what is the command line in meta/snap.yaml for the command that doesn’t work?

base: core18
- amd64
confinement: classic
grade: devel
    command: command-fsx.wrapper
m@mtp /s/f/x1> cat command-fsx.wrapper 
exec "fsx" "$@"

that’s a strange wrapper, what’s the relevant bit of your snapcraft.yaml like?

name: fsx # you probably want to 'snapcraft register <name>'
base: core18 # the base snap is the execution environment for this snap
version: '0.1' # just for humans, typically '1.2+git' or '1.3.2'
summary: F# scrpting tool # 79 char long summary
description: |
  FSX is the ideal tool for people that use F# for their scripting needs.

grade: devel # must be 'stable' to release into candidate/stable channels
confinement: classic # use 'strict' once you have the right plugs and slots

    command: fsx

    plugin: dump
    source: ./artifacts
    override-build: |
      echo "running sed"
      sed -i 's/mono .*fsx.exe.*/mono \$SNAP\/lib\/fsx\/fsxc.fsx.exe "$1"/' bin/fsx
      echo "running build"
      cat bin/fsx
      snapcraftctl build

why is it not bin/fsx?

classic confinement has no env vars set feeded in from plugins to avoid any conflicts with binaries, we have not defaulted away from wrappers for anything that has transitioned considering that command with wrappers is still more flexible than the command accepted by snapd. As an example, the hello snap which I recently transitioned to using bases exposes this problem.