4

As I've been learning more about Ubuntu and bash programming I've been storing variables in /tmp. For example in-between calls to the same bash script I want to record the previous state.

On my current single user system there is no danger of conflicts in /tmp directory. However I want my code to be future-proof and wonder if I should get in the habit of using a directory called ~/tmp?

Perhaps it should be ~/.tmp and hidden. Perhaps it should be ~/temp so as not to be confused with conventional /tmp directory.

Any ideas / suggestions are appreciated. Thank you.

1 Answers1

1

Generally if you wish to store the state for each user the easiest way is to just create a dedicated directory for the application in the users home directory:

CFGDIR="${HOME}/.mycoolapp"
mkdir -p ${CFGDIR}
# read / write files in ${CFGDIR} here..

If you just want a temporary storage for one instance of the script, a good approach is to use mktemp. For example:

TMPDIR="$(mktemp -d)"
# read / write files in ${TMPDIR} here..
rm -rf ${TMPDIR}
d99kris
  • 496