LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 02-08-2007, 10:43 AM   #1
nesta
Member
 
Registered: Aug 2006
Posts: 100

Rep: Reputation: 15
about subdirectories


hi folks,
i want to know a shell command that enables me to check that my current directory have some directories or not
and asolutly their names if possible?

i have tried test command but i cant do it.

thanks in advance.
 
Old 02-08-2007, 11:23 AM   #2
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 2,455

Rep: Reputation: 843Reputation: 843Reputation: 843Reputation: 843Reputation: 843Reputation: 843Reputation: 843
Code:
find . -maxdepth 1 -mindepth 1 -type d
or
Code:
for file in * .*; do if [ -d "$file" ] ; then echo "$file"; fi; done
 
Old 02-08-2007, 04:02 PM   #3
nesta
Member
 
Registered: Aug 2006
Posts: 100

Original Poster
Rep: Reputation: 15
thank u for wonderful answer
it is really so useful for me ,
i have used find command u sent but,
i want to save the result into a shell array variable

thanks in advance
 
Old 02-08-2007, 04:09 PM   #4
nesta
Member
 
Registered: Aug 2006
Posts: 100

Original Poster
Rep: Reputation: 15
when i tried the following:

directories=`find . -maxdepth 1 -mindepth 1 -type d`
echo $directories


i got ./folder1 ./folder2

but i want to access each of (folder1 and folder2)alone,how can i do that
i.e. i want to assign ./folder1 to a variable while
./folder2 to another variable
 
Old 02-08-2007, 06:18 PM   #5
Tischbein
Member
 
Registered: Oct 2006
Distribution: debian
Posts: 124

Rep: Reputation: 15
Here's a generic solution for getting the arguments one at a time. You can then put them into array cells, run code on them, whatever you please.

Code:
i=0

find . -maxdepth 1 -mindepth 1 -type d |\
while read dirname
do
    i=$((i+1))
    echo "Find number $i is called $dirname"
done
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert encoding through subdirectories? dl7und Linux - Software 2 04-16-2006 01:06 AM
Makefile and subdirectories pycoucou Programming 4 08-18-2005 04:43 AM
list all contains and subdirectories' contains babis Linux - Newbie 2 10-22-2004 09:40 PM
Unzipping all .gz files in all subdirectories darin3200 Linux - General 10 04-24-2004 09:58 PM
email and subdirectories hiertjou123 Linux - Newbie 5 07-16-2003 01:08 PM


All times are GMT -5. The time now is 05:45 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration