Nesting if in a for loop

Viewed 88125

I'm fairly new to bash scripts, so this is probably a stupid syntax error, but why is this code not working?

for x in $(ls)
do
  if [ -d $x ]
  then
  echo $x
  fi
done

The separate for and if section work fine on their own, but this produces no output.

4 Answers
#!/bin/bash

name=c
for command in "cd $home" " cd XSStrike" "python xsstrike.py"
do
    if [[ $name == "c" ]]; 
    then
        echo "<==========> access granted <==========>"
        $command
    else
        echo "<==========> access denied <==========>"
    fi
done
Related