I would like to use an environment variable I have declared in /etc/environment
as a counter which should be accessible to several unrelated scripts that are run at different times.
Is that possible? So far, I had no luck trying exporting its value.
I guess, I could always use a temporary file to store current value, read/write to it but I'm looking for a more elegant way if there is any?
The short answer is "No, you can't permanently change an environment variable from within a Bash script".
The longer answer is that when a Bash script is executed it receives a copy of the environment (not references to the environment variables themselves). So, whilst you can change the values of the copies within your script, those changes will be lost when the script exits and are also not visible to other scripts you may be running concurrently.
You can however, change an environment variable with a Bash script by "source"-ing it from the command line:
The changes will not be absolutely permanent but you can keep the changes to the environment variable as long as you are in the same login shell from which you executed the script.
There are multiple commands to execute a shell script, each command has it's own way to execute it. If you ran the script using the dot(.) operator, the script is executed within the same shell instead of opening another shell for the execution.
Hence, the changes to the environment variable made in that script will persist as long as it is executed using dot(.) and the shell from which it was executed is not closed.