How do I pass variable inside find and bash -c?

Hey guys, I'm having issues with passing variable to %exe part of the code. Need your help.

Here is my working code that I use inside bash script:

## Function
targz() {
  find $1 -type f -name "*.$2" -exec \
    bash -c 'old=$(basename {}); new=${old/%exe/tar\.gz}; \
      tar -zcvf $new $old; ' \;

## Function Call
## targz [directory] [extension]
targz . 'exe';

and yes I've tried using it some thing like this:


but it generates filenames like: file.exetar.gz



targz() {
  find $1 -type f -name "*.$2" -exec \
    bash -c 'old=$(basename {}); new=${old/'"$2"'/tar\.gz}; \
      tar -zcvf $new $old; ' \;

The trick is to get out of the single quote, so that variable expansion will be performed.

Need Your Help

Android support library v4 and Google Maps API breaks compilation

android eclipse google-maps-api-2 android-support-library

I'm trying to use the Google Maps API v2 in an android project that targets the v10 API.

iOS Send File to Review Application-Loader ( Apple Watch)

application-loader ios8-extension watchkit apple-watch

Can I send the apple watch apps For Review RightNow if Yes which file for review will be sent (Application-Loader) because we have a many file in Products Folder