2011-07-26 48 views
0

我正在編寫一個shell腳本,我需要將文件夾存儲在數組中的特定路徑中。列出指定路徑中的文件夾 - Shell腳本

如:$ DEST_FOLDER = /選擇/家庭的/ etc/

我需要在DEST_FOLDER子文件夾中存儲到一個數組。

在此先感謝。

回答

2
a=(`find "$DEST_FOLDER" -type d`) 

實施例:

[email protected]:~$ DEST_FOLDER=/home/susam/www/iptoc/p 
[email protected]:~$ a=(`find $DEST_FOLDER -type d`) 
[email protected]:~$ echo ${#a[*]} 
5 
[email protected]:~$ echo ${a[0]} 
/home/susam/www/iptoc/p 
[email protected]:~$ echo ${a[1]} 
/home/susam/www/iptoc/p/include 
[email protected]:~$ echo ${a[2]} 
/home/susam/www/iptoc/p/data 
[email protected]:~$ echo ${a[3]} 
/home/susam/www/iptoc/p/rss 
[email protected]:~$ echo ${a[4]} 
/home/susam/www/iptoc/p/files 
[email protected]:~$ echo ${a[5]} 

[email protected]:~$ 
相關問題