Bash script using sed & awk


I am trying to create a snap package that is based on a bash script but it used many systems tools like sed, awk, tar, OpenSSL, etc

Is there a possibility to create a snap package that executes or allows to execute a bash script that also interacts with different tools like the above mentioned?

Many Thanks

1 Like

As long as you ship the dependencies (sed, awk…) in your snap, you can use them in the bash script without a problem. See stage-packages in snapcraft.yaml for shipping packages not included in the base snap:


Thank you I will try it. If you have any example of how to include that I’ll do the rest :slight_smile:

1 Like

You should have access to many of the core command line utilities from the base snap (core or core18) without having to ship your own copy.

Here’s what the base AppArmor template allows:

So you can assume that awk, sed, and openssl are available.


Thank you this is exactly what I was looking for :slight_smile:

1 Like

how to use this? I’m getting my head around stagePackages syntax. Do I add these to stagePackages as

-   /{,usr/}bin/dd ixr,
-  /{,usr/}bin/diff{,3} ixr

Or do I simply add following in stagePackages list

- dd
- diff
1 Like

the apparmor rules mean that you have full access to these binaries from the base snap (i.e. core20 or core22) … since your app will use this as the rootfs in your execution environment at runtime, there is nothing you need to do, you can just use /bin/dd or /bin/diff directly without having them in stage-packages at all …

1 Like

Tried with base core18, I get xprop not found. This was the bash command which I used for this testing.

Well, indeed, only what is on the above list is available… other bits will still need to be staged, xprop is not in the apparmor list linked above nor is it even in the base snaps…

1 Like

got it. I do not fully understand the syntax for stagePackages, how should I add these additional commands

-   /{,usr/}bin/xprop ixr,


-   xprop
1 Like
$ apt-file search bin/xprop
x11-utils: /usr/bin/xprop 

so you want to stage the x11-utils package …

(stage-packages always only list debian packages from the ubuntu archive, so if you look for some binary you need to find the package name, apt-file is a good tool for this)


I added x11-utils in stage packages list, I still get the same error - xprop not found

1 Like

How exactly do you call it ? Note that it will live in $SNAP/usr/bin, this is also added automatically to your PATH variable inside the snap execution environment at runtime… so you should either call it without any path as xprop or with the full path including $SNAP… if your app hardcodes /usr/bin as the call to xprop, you can use a layout to map it to that location.

1 Like

I call it without any path i.e xprop. My bash file looks like this

xprop .....
1 Like

@ogra I have tried this multiple time, the issue persists. How do we debug this issue? Is there a way to read metadata of the packaged snap to compare if the package does have the stagePackages we included?