zsh conditional statement help
By Emma Johnson •
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
fiWhat am I missing?
2 Answers
turns out, i was missing the "then" after the if statement.
should be
if [[ "${whoa}" != "0" ]]
then do something
fi 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.