The fact: you need to know how many times a given script has been run lately. This task is quite trivial if you keep the number in a given temporary file.
What I am going to show you instead, is how to store the number just directly in the same script.
Oh well, not that this is too hard to do but it’s a nice trick that may give you an idea of how self-extracting script do work (e.g. nvidia official drivers and common linux games are shipped with this type of container).
Let’s go to the core of the problem: in order to distinguish the code from the data, we need to put the first on top of the file and then tell the shell interpreter when it has to stop reading. How we can do this? With exit, of course