0

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 
Kusalananda
  • 333,661

1 Answers1

0

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).

Kusalananda
  • 333,661