The output of:
find mydir -name foo -exec echo "---$(basename {})---" \;
should be ---foo---, but instead it is ---mydir/foo---
The command basename alone:
basename mydir/foo
echo "---$(basename mydir/foo)---"
brings respective foo and ---foo---
Replacing basename with other command such as uname the construct $(...) works correct.
Because
$(basename {})gets expanded to{}by bash before runningfindcommand, yourfindcommand is exactly equivalent to :That's why you see
---mydir/foo---To get the effect you wanted, you can do :