Hey everyone, I'm fairly new to both unix and shell scripts. Right now I have a script that I can run in one folder (if a certain text file is there, do one thing, if it's not, do something else). I want to modify this to run in multiple directories. My setup is: a company directory, and within it directory c1, c2, c3, etc. I assume that I have to use some recursive call or looping to tell the script to run on every directory, but I haven't been able to figure it out from searching online. Thanks!
cd directory
find . -print -type d |
while read dirname do
cd $dirname
# run your code at this point
cd -
done
Thanks, this is exactly what I was looking for.
edit: This is the current state of my code, and it almost does what I'm looking for--how can I make the loop exclude the root directory companies? I only want this to happen in the immediate subfolders.
cd companies
find . -type d -print |
while read dirname
do
cd $dirname
if [ -f "changes.txt" ]; then
#some code
else
#some other code
fi
cd -
done