#!/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 "" ]]
.
#!/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 "" ]]
.
Test string equality with =
.
#!/bin/bash
export PROCNAME=test
export TABLE_ID=0
if [ "${TABLE_ID}" = "" ]; then
echo hello
fi
You can use -z
to test if a variable is empty:
if [ -z "$variable" ]; then
...
fi
From man test
:
-z STRING
the length of STRING is zero
See an example:
$ r="roar"
$ [ -z "$r" ] && echo "empty" || echo "not empty"
not empty
$ r=""
$ [ -z "$r" ] && echo "empty" || echo "not empty"
empty
#!/bin/bash
export PROCNAME=test
export TABLE_ID=0
[ -z ${TABLE_ID} ] && echo hello