for-loop for every folder in a directory, excluding some of them

You can use continue to skip one iteration of the loop:

for d in this_folder/*    
    do    
        plugin=$(basename $d)
        [[ $plugin =~ ^(global|plugins|css)$ ]] && continue
        echo $plugin'?'
        read $plugin
    done

If you meant to exclude only the directories named global, css, plugins. This might not be an elegant solution but will do what you want.

for d in this_folder/*    
do  
    flag=1
    #scan through the path if it contains that string
    for i in "/css/" "/plugins/" "/global/"
    do

    if [[ $( echo "$d"|grep "$i" ) && $? -eq 0 ]]
    then
      flag=0;break;
    fi
    done

    #Only if the directory path does NOT contain those strings proceed
    if [[ $flag -eq 0 ]]
    then
    plugin=$(basename $d)
    echo $plugin'?'
    read $plugin
    fi


done

If you have a recent version of bash, you can use extended globs (shopt -s extglob):

shopt -s extglob

for d in this_folder/!(global|plugins|css)/   
do    
    plugin=$(basename "$d")
    echo $plugin'?'
    read $plugin
done

Tags:

Bash

For Loop