[: -eq: unary operator expected

user2711819 picture user2711819 · Jan 30, 2015 · Viewed 11.4k times · Source
#!/bin/bash    
export PROCNAME=test
export TABLE_ID=0

if [ ${TABLE_ID} -eq "" ]; then
        echo hello
fi

above throws error:

[: -eq: unary operator expected

How to fix this with out double square brackets [[ ${TABLE_ID} -eq "" ]].

Answer

Mars picture Mars · Jan 30, 2015

Test string equality with =.

#!/bin/bash    
export PROCNAME=test
export TABLE_ID=0

if [ "${TABLE_ID}" = "" ]; then
    echo hello
fi