How to design reusable script handling temporary files lifecycle for other scripts
0
votes
2
answers
253
views
I need to create a reusable ("utility") script handling entire set of operations with temporary files for any of my other ("application") scripts:
1. creation
2. tracking of temporaries created
3. trapping exit (regular completion and interruption by user) and removing everything created
Each of application scripts need to "include" utility script on their own, not rely that some "main" script will call it once for all subscripts it uses.
The key requirement is that application scripts using the utility script can call each other, each of them in turn also need to use temporary files. Call between scripts are both
./some_script.sh
and
. ./some_script.sh
Some scripts exit with error code; others just finish without explicit
exit
. The application scripts themselves can be called from command line using subshells, like:
echo "Parameter" |
./feed_parameter_to_script.sh script_using_tmps.sh
Ideally application scripts could invoke creating temporaries from subshells within its own code, but that's not mandatory.
The only solution I found is [for each script to perform its tmp removal on its own](https://superuser.com/a/1226160) , which does not fit item 3. in my requirements.
What is best practice for requirements like mine?
Asked by wass rubleff
(163 rep)
Jul 20, 2022, 02:03 PM
Last activity: Jul 20, 2022, 04:50 PM
Last activity: Jul 20, 2022, 04:50 PM