7 ms·
I usually put the process PID in the names of my temporary files, in order to avoid overwriting stuff. (If you're liable to do multiple runs with the same proce
by enkiv2 8y ago
I usually put the process PID in the names of my temporary files, in order to avoid overwriting stuff. (If you're liable to do multiple runs with the same process, you can generate a random number at the beginning of the task -- or get the date, if you really want to keep the results in order -- and use it as a unique token.)
I first prototype operations as single command lines, then refactor those command lines as I migrate components of them to shell functions (often taking whatever unique token I want to use to distinguish runs). Eventually, when I'm satisfied with the behavior, I'll write the shell functions to a script with typeset -f, and then source the script later.
While it's not research-related (a lot of what I do at work is statistical analysis on server logs, but anything I develop at work I technically don't own & so can't post), a good example of this style is in my music synthesizer project: https://github.com/enkiv2/clisynth/blob/master/clisynth.sh https://github.com/enkiv2/clisynth/blob/master/clisynth.sh ; all of the code in this file was prototyped at the command line.
- 0db532a0 8y agoI never considered defining functions as I go. That is a good idea. Previously I've just relied on readline. typeset is a new find. It might be good to have a function, which when called by another function, generates a file name associated with the calling function's name, using mktemp. It could even add the calling function's name plus its arguments to a log file.