10

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
  • 115
  • 4

1 Answers1

5

Use -d to check:

if [ -d "$f" ]; then
Reut Sharabani
  • 30,449
  • 6
  • 70
  • 88