bash scripting question

let_s_begin

New Member
Joined
Jan 16, 2020
Messages
4
Reaction score
0
Credits
14
i was picking apart some bash scripts online to help me practice and learn more about bash. i encountered one script that had this ((count++)) towards the end of the script. from what i can tell this says to add to the variable. i was hoping for a better explanation about what it does, why its there, and hopefully some examples of its use in other scripts.

Here's the script

#!/bin/bash
valid=true
count=1
while [ $valid ]
do
echo $count
if [ $count -eq 5 ];
then
break
fi
((count++)) #this is what i was curios about
done
 


hint: count = 1

you have a loop after this, what does it do?
while (waiting for something to be true)
do (something)
echo the value of $count
if the value of count equals 5, then break (stop running this script)

question. If the value of count starts off = 1
and we have a loop that is waiting for count to equal 5.

It probably does something to the value of count.
what would you guess that count++ does?
 
And -eq means equal to so loop goes
2
3
4
5
At 5 breaks out of loop
 

Members online


Top