find -exec in bash script with variable expansion

view full story

http://unix.stackexchange.com – I'm trying to run a command similar to the one below in a bash script. It should search through all subfolders of $sourcedir and copy all files of a certain type to the root level of $targetdir. #!/bin/bash # These are set as arguments to the script, not hard-coded sourcedir="/path/to/sourcedir" targetdir="/path/to/targetdir" find "$sourcedir" -type f -name "*.type" -exec sh -c 'cp "$1" "$2/`basename "$1"`"' "{}" "$targetdir" \; This seems to be pretty close, except that {} isn't being passed in as $2 to "-exec sh -c ..." I would like to do this as close to the "right way" as possible, w (HowTos)