Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
if [[ ${whoa} -gt 0 ]]
    do something

What am I missing?

share|improve this question
up vote 3 down vote accepted

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

should be

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

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .