Symllinks, aliases, and argv[0]

I have a snap (devoperator) which contains a tool authwrapper which is designed to wrap around thinks like kubectl and eksctl. I had hoped to simply symlink eksctl -> /snap/bin/authwrapper or perhaps use snap alias.... My script would then look at argv[0] and go from there. No dice. The value of argv[0] always ends up being something like /snap/devoperator/x2/bin/authwrapper

Any ideas for how to do what I want?

I’m afraid that snapd is using the same trick to determine which app to execute (do an ls -l on the stuff in /snap/bin and you’ll see what I mean), which means argv[0] isn’t what the USER ran so much as what snapd is running, which is going to be the command you specified.

@ijohnson is there a way to determine, from the app, if it was called with an alias?

I don’t think so.

This is because like @kyrofa explained, snapd is already doing the same thing for snap apps and aliases, in order to run them from inside confinement with /usr/bin/snap. The argv[0] you see in your snap will always be whatever is in the snap.yaml for your app, so if you snap has command: bin/authwrapper you will always see argv[0] as bin/authwrapper, regardless of any symlinks that were used to execute the snap (and in fact symlinks to things in `/snap/bin/… will not work at all).

Is there a reason you can’t just have your users do:

$ authwrapper eksctl something k8s related

The biggest reason is that tab-completion for eksctl doesn’t work if you type authwrapper eksctl .... I might have to stop shying away from understanding bash completion. :-/

Thanks guys