#!/bin/bash
echo "setup"
mkdir -p ~/test/find/{1,2,3}
mkdir ~/test/find/1/{a,b,c}
touch ~/test/find/1/a/a.file ~/test/find/1/b/b.file ~/test/find/1/c/c.file

echo "With echo find outputs for all three a.file, b.file, and c.file"
find ~/test/find/1 -iname "*.file" -exec bash -c 'set -x; echo cp "$1" ~/test/find/2/ && echo mv "${1%/*}" ~/test/find/3/' -- {} \;

echo "But when echo is removed, find only works on the first."
find ~/test/find/1 -iname "*.file" -exec bash -c 'set -x; cp "$1" ~/test/find/2/ && mv "${1%/*}" ~/test/find/3/' -- {} \;

echo "Changing mv to cp -r then does more than one"
find ~/test/find/1 -iname "*.file" -exec bash -c 'set -x; cp "$1" ~/test/find/2/ && cp -r "${1%/*}" ~/test/find/3/' -- {} \;

echo "cleanup"
rm -r ~/test/find
