#!/bin/bash
RED='\033[0;31m'
NC='\033[0m'
Bokoblin_HP=30
Bokoblin_STR=5
Link_HP=60
Link_STR=10
while [ $Bokoblin_HP -ne 0 ]
echo "Bokblin HP : ${Bokoblin_HP}/30"
do
read -p "Press A to Attack or Press H to Heal : " action
if [ $action = "A" ]
then
((Bokoblin_HP=$Bokoblin_HP-$Link_STR))
echo $Bokoblin_HP
fi
done
Result :
Bokoblin HP : 30/30
Press A to Attack or Press H to Heal : A
30
I'm doing an operation on Bokoblin_HP and I would like to stop the program when it reach 0, but my variable won't change and still 30.
bash? A shell likedashwill treat((...))as a nested sub shell, not an arithmetic command. TryBokoblin_HP=$((Bokoblin_HP - Link_STR))instead.read -p. The echo in the while condition is the culprit, try it.echo $Bokoblin_HPcontinues to output30after the supposed update. Good point aboutread -P.