Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unary operator expected in Bash

I've seen questions regarding the same issue, but all of them are about strings. How about integers? Why am I getting the "unary operator expected" error?

 if [ $(date +%k%M) -ge ${!BLOCK1FRAN} ] ; then whatever ; fi
like image 628
Paolo Avatar asked Apr 01 '14 22:04

Paolo


1 Answers

You are using indirection. If the variable ${BLOCK1FRAN} points to an empty variable, you'll get the error message. Make sure that the variable pointed by ${BLOCK1FRAN} contains a valid numeric value.

If you want an empty string and nonnumeric values to be evaluated as zero (0), use the following syntax.

if [[ $(date +%k%M) -ge ${!BLOCK1FRAN} ]]; then whatever ; fi
like image 107
alvits Avatar answered Nov 18 '22 07:11

alvits