I have a bash script. I would like this script to do something different every time I call it (modulus three). Something like this :
First script call => echo "call 1"
Second script call => echo "call 2"
Third script call => echo "call 3"
Fourth script call => echo "call 1"
Fifth script call => echo "call 2"
Sixth script call => echo "call 3"
Seventh script call => echo "call 1"
...
What would be the simplest way to do this ?
Note that the script is not critical. For example : the counter can go back to one after a reboot :
...
n script call => echo "call 1"
n+1 script call => echo "call 2"
* reboot *
n+2 script call => echo "call 1"
...
is OK.
Thank you for your insights.
In Bash:
call=$(< call.txt)
case $call in
0) do_thing_one;;
1) do_thing_two;;
2) do_thing_three;;
*) do_oops_thing;;
esac
echo $(( (call + 1) % 3 )) > call.txt