The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




Thread: foreach folder
View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #7 (permalink)  
Old 08-13-2007
eltinator eltinator is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 63
Quote:
Originally Posted by lorcan View Post
A small correction blowtorch.

Code:
for file in *; do
   if [ -d $file ]; then
      mkdir $file/test; 
   fi
done
Since you had issued a cd command it would create the sub-dir only for the first directory. So the result would not be as expected.
Hi, I had a question about the cd thing, how come it doesn't work? I'm modifying the code to go into certain subfolders in each folder and then execute a command so I wasn't sure how to do that. Basically I'm trying to do something like this now...

current directory:
a b c

Inside of each directory there is a file here (using a as an example):
a/test/folder/script.sh

Sorry for the generic names. Now what I want my script to do is access that script.sh in each folder and run it. I was gonna do the for statement and then cd into that path and then do an execute command but I guess it's not that simple. Any ideas? thanks!