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?

link|improve this question

73% accept rate
feedback

2 Answers

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.

link|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
feedback
up vote 1 down vote accepted

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

should be

if [[ "${whoa}" != "0" ]]
then
    do something
fi
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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