Session-Independent Persistent Variable in RAM

I wrote a small ash shell script that toggles an action:

  • Call #1, #3, #5, etc :arrow_forward: Action A
  • Call #2, #4, #6, etc :arrow_forward: Action B

To do so, the script updates a file in which the last action is stored.
I did so for the script to be session independent.

I would like to write a similar script but not relying on a file saved on the hard drive to reduce its wear.
I would like to use instead a session-independent persistent variable in RAM.

I tried to use an environment variable (export last_action=A), but noticed it is initialized every time a new session starts and doesn't hold the latest updated value from one session to another.

Do you know how/if I can use a session-independent persistent variable in RAM?

I think I will create/update a file (called last_action containing A or B) located at /dev which is a filesystem of the type tmpfs, thus located in RAM (df to check filesystem type).

if ! uci -q -c /tmp/etc show script > /dev/null
then
uci -c /tmp/etc import script < /dev/null
uci -c /tmp/etc set script.conf="conf"
fi
uci -c /tmp/etc set script.conf.last_action="A"
uci -c /tmp/etc get script.conf.last_action
1 Like

Thank you!
I didn't know about this uci command. I will have a look at it.
Currently working with a file stored at /tmp (or /dev) does the trick but there is definitely room to improve my script.

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.