I'm ALL NEW in shell script , hence have a question about how to round up integer.
Here is a line of the code from a script by keke(smstools3 developer)
balance=$(substr "$result" "$balance_prefix" "$balance_suffix")
And my balance is 111.12
, and I wish to round it up.
I tried
balance1=$(substr "$result" "$balance_prefix" "$balance_suffix")
balance=$("%0.f\n" "$balance1")
or
balance1=$(substr "$result" "$balance_prefix" "$balance_suffix")
balance=$(ceil($balance1))
Both refer from some answers after google it , I not even know if the syntax is correct.And of course both example return blank.
Any hints or advice?Thank you.
Edit:
# Check that required words exists:
if [[ "$result" == *${balance_prefix}* ]] && \
[[ "$result" == *${balance_suffix}* ]]
then
# Get the balance and check it:
balance=$(substr "$result" "$balance_prefix" "$balance_suffix")
balance_low=0
if [ $(expr "$balance" + 1 2> /dev/null) ]; then
[ $balance -le $alert_balance ] && balance_low=1
else
echo "Error while parsing an integer: $balance"
fi
else
echo "Error while parsing the answer (balance): $result"
fi