2016-08-23 47 views

回答

0

當迪爾斯是沒有空間,你可以做

subpath="" 
for dir in $(echo "/path/to/some/place" | tr "/" " "); do 
    subpath+="/${dir}" 
    echo "$subpath" 
done 

/path 
/path/to 
/path/to/some 
/path/to/some/place 

當你有更復雜的dirnames(並且總是假設你有),你需要另一個解決方案。

myvar="/path/to/some/place" 
IFS=/ read -ra d <<< "$myvar" 
for dir in ${d[@]}; do 
    subpath+="/${dir}"; 
    echo "${subpath}" 
done 
相關問題