Wrong test interpretation for simple function.

Hello everyone,
I have written simple script below to check if ip is added to interface

#!/usr/local/bin/bash

IFCONFIG="/sbin/ifconfig"
SERVICE="/usr/sbin/service"
IP="79.137.X.X"

GREP=$(${IFCONFIG} | grep ${IP})

ip_quantity_check () {

        echo ${GREP} | wc -l

}


if [[ ip_quantity_check -gt 0 ]]; then
        echo "IP is linked"
else
        echo "Nie jest"
        exit 1
fi

When i use only ip_quantity_check function im getting "1" as should be and this is ok. But when i put function into the test "[[ ]]", im getting some wrong interpretation of it becouse i always get:

else
echo "Nie jest"

Where is a problem ?
Thank you,

You need to deploy "command substitution" as well for shell functions:

if [[ $( ip_quantity_check) -gt 0 ]] ...

OR use the function's exit code (which can be modified in the return statement) like

if ip_quantity_check; then ...
1 Like

Ahh, you are right. It's working now.

Thank you !