I don't write a lot of Bash, so I'm a bit stumped as to how to fix this. I need to check whether a value returned from a command is greater than x
. When it runs though I get [: -gt: unary operator expected
which I'm unable to fix.
Here is my script,
#!/bin/sh
ERROR=0
PHPCPDLevel=100
# PHPCPD
echo "PHP CopyPaste Detection (Limit is at least ${PHPCPDLevel}%"
PHPCPD="phpcpd ."
if [[ `echo $PHPCPD | grep "%" | cut -d'.' -f1` -gt "$PHPCPDLevel" ]]
then
echo $PHPCPD
ERROR=1
else
echo "... -> Only `echo $PHPCPD | grep "%" | cut -d'.' -f1`%"
fi
echo "Finished!"
exit $ERROR
Update: I think I've done it:
#!/bin/sh
ERROR=0
PHPCPDLevel=25
# PHPCPD
echo "PHP CopyPaste Detection (Limit is at most ${PHPCPDLevel}%)"
PHPCPD="phpcpd ."
PERCENTAGE=$($PHPCPD | grep "%" | cut -d'.' -f1)
if [ ${PERCENTAGE} -gt ${PHPCPDLevel} ]
then
echo $PHPCPD
ERROR=1
else
echo "Only $PERCENTAGE%"
fi
exit $ERROR