batty
batty

Reputation: 597

List folders in specified path - Shell script

Im writing a shell script where I need to store the folders in a particular path in an array.

Eg: $DEST_FOLDER = /opt/home/etc/

I need to store the subfolders in the DEST_FOLDER into an array.

Thanks in advance.

Upvotes: 0

Views: 739

Answers (1)

Susam Pal
Susam Pal

Reputation: 34254

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

Example:

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

susam@nifty:~$

Upvotes: 2

Related Questions