I cant post a comment so I'me just going to crate a new post.
The Problem analyzes
As far as i know there is no shell comand (part of the corr of bash) that is used to cash data... how ever that dose not mean that there are no means to implement it...
How ever how you want to actually implement it is entirely dependent on you're distributions enviroment and what file structure it is is build on.
Filesystem Hierarchy Standard (wiki)
Go to the section about FHS compliance, and what it will basically tell you is not all Linux distribution are created equally (case and point different shell version across different distribution aka bourn shell vs kornshell)...
Somme may include the /dev/shm Somme may not... Thats why you got the message:
ls: /dev/shm: No such file or directory
you're distrubution apparently is one with out the file /dev/shm !!!
Most Linux distributions follow the Filesystem Hierarchy Standard and
declare it their own policy to maintain FHS compliance.
So Now my question what is a good way to deal with this conundrum? well i would say its rather simple...
Create a list off all potential directory which store in memory instead of on the hdd
and create a if elif conditional where you check if a file exists or not.Should one of the files exist (which is more then likley, unless they changed the file structure)
You can then just simlpy declare a variable called temp and fill it with the path of the tmpfs (temporary filesystem)
To give you a gist of it
#/run directory as a temporary filesystem (tmpfs)
#which stores volatile runtime data, following the FHS version 3.0.
if [ -e /run ]
# with FHS version 2.3, such data were stored in /var/run
#for compatibility there might be a simlink
elif [ -e /var/run ]
elif [ -e /dev/shm/]
elif [ -e /var/tmp ]
#this should not occur with the current fhs standerts
#switching to /var/tmp just in case ;)
This is just to give you a basic idea (I'm still working on it my self(for my final project ;)
but i believe this could be helpful for others. What you could now do is just create a file in the directory with the name of the process followed by a time stamp to create a cronjob to automatically clean up you're temporary fills in regular intervals or just by calling the rm command when you no longer require the file.
PS If you find any further tmpfs pleas just go a head and edit this post Thanks.