I need to perform an arithmetic operation inside a bash loop as explained below
CYCLE?=3
COUNT=1
download_when_ready: ## Will try the download operations many times till it succeeds or it reaches 10 tries
while ! composer update $(bundle) 2> /dev/null && [[ $(COUNT) -lt 10 ]]; \
do \
COUNT=$$(( $(COUNT)+1 )); \
SLEEP=$$(( ($(COUNT) / $(CYCLE)) + ($(COUNT) % $(CYCLE)) )); \
echo "count $(COUNT)"; \
echo "cycle $(CYCLE)"; \
echo "sleep $(SLEEP)"; \
sleep $(SLEEP); \
done
This never stops and gives the following:
count 0
cycle 4
sleep 0
count 0
cycle 4
sleep 0
....
count 0
cycle 4
sleep 0
As you can see, variables have the initial values and never change !
UPDATE
PRETTY_NAME="SUSE Linux Enterprise Server 11 SP4"
However the following code keeps the value of $$c
empty, before the while loop and inside it.
CYCLE?=3
COUNT=1
download_when_ready: ## Will try the download operations many times till it succeeds or it reaches 10 tries
@c=$(COUNT);
@echo $$c;
while ! composer update $(bundle) 2> /dev/null && [[ $(COUNT) -lt 10 ]]; \
do \
echo "$$c"; \
done