separate file and path in bash?

Solution 1:

You can't. But you can do them separately.

$ foo=/usr/local/bin/bar
$ echo "${foo##*/}"
bar
$ echo "${foo%/*}"
/usr/local/bin

Solution 2:

I would suggest dirname and basename:

for file in `find /my/path -name "*.ext"`
do
    path="$(dirname "$file")"
    onlyfile="$(basename "$file")"
    # ...
done