
如何在這樣的 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