9

So I'm scanning through a directory and want to test if each element of the directory is a directory:

FILES=$PWD/*

for f in $FILES 
do
  if [ $f is a directory ]; then #Correct conditional needed here
    echo "Dir: $f"
  fi       

done

What method/function do I use to test if $f is a directory?

Quantum88
  • 105
  • 3

1 Answers1

4

Use -d to check:

if [ -d "$f" ]; then
Reut Sharabani
  • 29,003
  • 5
  • 68
  • 85