![在 bash 中分离文件和路径?](https://linux22.com/image/1320409/%E5%9C%A8%20bash%20%E4%B8%AD%E5%88%86%E7%A6%BB%E6%96%87%E4%BB%B6%E5%92%8C%E8%B7%AF%E5%BE%84%EF%BC%9F.png)
我怎样才能在这样的 bash 循环中分离路径和文件元素?
for file in `find /my/path -name "*.ext"`
do
#(path,onlyfile) = separate_path_and_file $file
#dosomethingwith $onlyfile
done
答案1
你不能。但你可以分别进行。
$ foo=/usr/local/bin/bar
$ echo "${foo##*/}"
bar
$ echo "${foo%/*}"
/usr/local/bin