LinuxQuestions.org
Help answer threads with 0 replies.
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 06-04-2004, 08:28 AM   #1
linuxzouk
Member
 
Registered: Apr 2004
Location: Malaysia
Distribution: Fedora Core
Posts: 93

Rep: Reputation: 15
directory listing script


how do i write a simple script to list out only directories and
then pass the directories into a parameter one by one

while not_end_of_directory_list do
cd $directory
excute a command
cd..
end

so far, i can get the directory list
directory=`find . -type d`
but how do i pass in one by one and
also without the '"." in the $directory

thanks in advance
 
Old 06-04-2004, 10:44 AM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
Code:
#!/bin/ksh

(find / -type d -print) |
while read dirname
do
    cd $dirname
    echo "We are in the $dirname directory"
done
 
Old 06-04-2004, 01:07 PM   #3
linuxzouk
Member
 
Registered: Apr 2004
Location: Malaysia
Distribution: Fedora Core
Posts: 93

Original Poster
Rep: Reputation: 15
thanks for you tip

i only want to enter current directory (1 level), so with a bit modification this done the job. thanks again

home=`pwd`
(ls -l | grep ^d | awk '{ print $9 }') |
while read dirname
do
cd "$home/$dirname"
echo "We are in the $dirname directory"
done

Last edited by linuxzouk; 06-04-2004 at 01:56 PM.
 
  


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
Listing Directory Size andy7t Linux - Software 2 12-14-2008 03:46 PM
Apache Directory Listing Of NFS Mount, cannot view directory list via apache luqmana Linux - Networking 2 12-19-2005 07:03 AM
Directory listing - Calling shell script from a CGI script seran Programming 6 08-12-2005 12:08 AM
Directory Listing mattbeekler Linux - Software 8 07-22-2003 03:27 PM
Java Directory Listing markdw Programming 1 04-16-2002 07:06 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:33 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration