Question

I would like to run a .sh script present in each subfolder named Gex_experiments according to the following folder structure:

Folder1       
--FolderA    
  --Gex_experiments     
--FolderB     
 --Gex_experiments     
--FolderC    
 --Gex_experiments    
.......      
--FolderAYCD
 --Gex_experiments

To run the .sh script present in the first level of subfolders (FolderA, FolderB, FolderC, ...) in the past I used the following script:

for i in *;   
do     
    cd $i;   
    qsub myscript.sh;    
    cd ..;    
done

but now I'm not able to enter in the subfolders Gex_experiments where in this case the script I would like to run is present.
Can anyone help me please?

Était-ce utile?

La solution

If you start in Folder1, you could do:

for i in */
do
    (cd "$i"Gex_experiments && qsub myscript.sh)
done

The trailing slash */ means that only directories will be found. The ( ) surrounding the loop mean that the command is run within a subshell, so you don't need to cd back out.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top