I'm trying to call a function from an if statement that is inside a for loop. I need to send the $i in "for i in *" to a function but i can find nothing that works.

ex.

# Perform actual file grab
for i in /Users/* ; 
   do
     if [[ -d $i && $(excludedDir $i) ]]; then
         echo $i;
     fi ;
done

Can anyone hep?

Re: Passing arguments to functions inside if statements 80 80

Your problem may be that the excludeDir is running in a subshell and not giving you the effect you want. Perhaps something like the following would work?

for i in /Users/*; do
    if [[ -d ${i} ]]; then
        excludeDir ${i}
        if [[ $? -eq 0 ]]; then
            echo ${i}
        fi
    fi
done
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.