Reputation: 31050
for subdir in $( find $dir -type d ); do echo "subdir is $subdir" done
the proble is that if the sub directory name contains space, they get separated, how do I resolve this?
Upvotes: 1
Views: 53
Reputation: 84579
oldifs=$IFS
IFS=$'\n'
for subdir in $( find $dir -type d ); do
echo "subdir is $subdir"
done
IFS=$oldifs
example:
$ bash dirnm.sh a
subdir is a
subdir is a/dir 1
subdir is a/dir 2
Upvotes: 0
Reputation: 799102
for subdir in $somedir/*/ do
echo "subdir is $subdir"
done
If you continue to have problems with spaces then you've goofed up your quoting elsewhere.
Upvotes: 0
Reputation: 785541
You can use process substitution
:
while IFS= read -d '' -r subdir; do
echo "subdir is $subdir"
done < <(find "$dir" -type d -print0)
Upvotes: 1