I tried:
for item in *
do
if [ -d ${item} ]
then
echo "$item"
fi
done
and when a file name with space is read it prints error:
line 11: [: too many arguments
I tried:
for item in *
do
if [ -d ${item} ]
then
echo "$item"
fi
done
and when a file name with space is read it prints error:
line 11: [: too many arguments
Quote the expansion of $item
, just like you're already doing with echo
:
for item in *; do
if [ -d "$item" ]; then
echo "$item"
fi
done
Related:
Note also that adding a /
to the end of the pattern will force matching of subdirectories (if anything matches).