I believe the variable substitution occurs before it gets passed to the exec command. You will need to write a simple plugin to convert the variables before passing it to the exec command. Hope that helps.

The easiest solution I found for this is to use the build system as a proxy for exec, which then lets you use $file, $file_name, etc.

Go to Tools > Build System > New Build System, copy and paste your old build system into here, or just edit your old build system, and then add a variants section, give it a name, and all the other commands you want. Then add a new keyboard shortcut and add an args with the variant name.

Now when I press ctrl+b with a .go file open it runs the build command which executes my bash script "sublime-go-build" which is in my system's $PATH with three arguments, $1=$file, etc. If I press ctrl+shift+b it does the same thing with "sublime-go-test" instead. You can add as many variants as you want and set them to whatever keyboard shortcuts that you want. One advantage is that now you can run this only on the language files you want, one disadvantage is that you have to add this to every languages sublime build file.