J Warrior777 J Warrior777 - 27 days ago 7
Linux Question

Linux syntax errors

I`m trying to run a bash script but for some reason this part of the output is giving me an error.

TIER1PCT=$[ $TIER1COUNT * 100 / $TOTAL ]
TIER2PCT=$[ $TIER2COUNT * 100 / $TOTAL ]
TIER3PCT=$[ $TIER3COUNT * 100 / $TOTAL ]


I am receiving this error:
:syntax error: operand expected (error token is "/ ")

Answer

try this;

TOTAL=$(cat $NEWUSERSFILE | wc -l)

if [ -n "$TOTAL" ]; then
TIER1PCT=$[ $TIER1COUNT * 100 / $TOTAL ]
TIER2PCT=$[ $TIER2COUNT * 100 / $TOTAL ]
TIER3PCT=$[ $TIER3COUNT * 100 / $TOTAL ]

else 
echo  $TOTAL is null
fi
Comments