-1

when I run this script in my Ubuntu:

   for item in *
do
    if  [ -d $item ]
    then
        echo $item
    fi
done

I got this output: output

I don't understand why I get "[: if-then: unexpected operator"

Victor
  • 9
  • 2
  • 1
    Please don't post any text as image. Read [how-to-ask](https://stackoverflow.com/help/how-to-ask). – KamilCuk Sep 20 '18 at 06:53

1 Answers1

-1

Escape your variables. Read about it here.

for item in *
do
    if  [ -d "$item" ]
    then
        echo "$item"
    fi
done
KamilCuk
  • 120,984
  • 8
  • 59
  • 111