Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Feeling kinda dumb right now:

Why is my contional always true?

I've tried

# this should let me know what's not a directory or 
# symbolic link.
whoa=`find ${MUSICDIR} ! -type l ! -type d | wc -l`

# I would expect if it's 0 (meaning nothing was found) that
# one of these statements would evaluate to false, but so far
# it's always evaluating to true
if [[ "${whoa}" != "0" ]]
    do something
fi
if [[ ${whoa} -gt 0 ]]
    do something
fi

What am I missing?

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

turns out, i was missing the "then" after the if statement.

should be

if [[ "${whoa}" != "0" ]]
then
    do something
fi
share|improve this answer
add comment

The backticks collect stdout of the subprocess, and whoa will contain the text, not the errorlevel. You can use $? to get the errorlevel of the last command.

But if you're using find you can use its exec feature to do something.

Also, you can use type f for file, to find a regular file.

share|improve this answer
    
turns out, i was missing the "then" after the if statement. I know i can use "-type f", and I probably should. Just just nervous i'll miss something else. Thanks for the quick reply –  Roy Rico Feb 13 '11 at 23:38
    
@Roy: You should post that as an answer and accept it. –  Dennis Williamson Feb 13 '11 at 23:43
    
@Dennis meta question: if you post a question and answer it yourself do you get points? –  Keith Feb 13 '11 at 23:44
    
Not from yourself, but others can upvote your question and your answe. –  Dennis Williamson Feb 13 '11 at 23:52
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.