Suppose I am at the main directory which contains script.sh and subdirectories, each of subdirectories contain images.
The script.sh is a script for resizing images. I want to apply this script to every subdirectories, so after searching for solution I created another script which is
SAVEIFS=$IFS #Since the subdirectories contain whitespaces in their name
IFS=$(echo -en "\n\b")
for d in ./*; do
if [ -d "$d" ]; then
echo "$d" && cp ./script.sh ./$d/script.sh && cd "$d" && exec sh ./script.sh && cd ..
fi
done
IFS=$SAVEIFS
The problem is this script stops after it's done at the first subdirectory. How can I make it runs for all subdirectories? Or are there better way to make script.sh runs for all subdirectories?