bash에서 별도의 파일과 경로가 있습니까?

bash에서 별도의 파일과 경로가 있습니까?

이와 같이 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

답변2

내가 제안 할게dirname그리고basename:

`find /my/path -name "*.ext"`에 있는 파일의 경우
하다
    path="$(디렉터리 이름 "$file")"
    onlyfile="$(기본 이름 "$file")"
    # ...
완료

관련 정보