Bash/Shell Programming – Binary Operator Expected

So if you ever decide to get into shell scripting, it’s a wonderful world.  Until you run into snags that you once thought you had the hang of.  Let’s take shell conditionals, for example.

So i’m trying to test the output of grep and do something if it returns a result.  After setting it up the usual way:

if [ -n `ls | grep something' ]; then
echo "Something Exists";

But by doing it that way, I kept getting the error:
./ line 3: [: 2841.c: binary operator expected
which for the life of me I couldn’t figure out. Eventually I figured it out though…and all that the error was, was instead of a single ‘[‘ and ‘]’ wrapping the comparison, it requires a double…i.e.

if [[ -n `ls | grep something` ]]; then
echo "Success";

Hope this saves someone some headache in the future.