2

I'm using a program which processes some data and then saves it to a file. It is possible to specify the directory in which the data is saved, however the program is badly written, so if I put ~ it is unable to interpret the result and says that no directory named /~ is found.

I want to be able to give this program to my colleagues and have them run it. I could just directly specify to save in /home/my_username/, but then they would also get "no directory found" when they try to run it, because their home folders have different names.

Can I specify ~ in some other way that my colleagues can run the program and have it save their data in their own respective home directories?

1
  • 1
    Is this program taking the path as a parameter as a command line argument, from a properties file, or is it hard coded. If it is hard coded, which language?
    – Usi
    Mar 8, 2016 at 19:40

4 Answers 4

3

Note that ~ is expanded by the shell to the value of ${HOME}, you can't enter that as input to a program and expect it to automatically translate it to ${HOME} (unless you specify it as a command-line option to the program, which gives the shell a chance to perform the substitution).

If you want to write to the home directory, you could have your program look up the ${HOME} environment variable. Then whoever it is, and where ever home is, you'll get the right answer.

1

I'd be inclined to suggest trying . (yes, just a dot). This means current directory.

So if the program is being run from a user's home directory, that's where it will save its data.

1
  • A far better idea than mine.
    – Jenny D
    Mar 9, 2016 at 9:03
0

I'd recommend using /tmp. It's world writable (or, at least, if it's not world writable, you have much bigger issues than which directory to use!).

4
  • Possibly first with mktemp -d unless the vendor makes a user-private temporary directory already.
    – thrig
    Mar 8, 2016 at 18:54
  • @thrig Given the constraints in the question, I am sceptical that the program would be able to handle the substitution required to deal with different temp dirs for different users. Also, since the poster suggested using /home, there would seem to be little requirement for privacy.
    – Jenny D
    Mar 8, 2016 at 18:59
  • 2
    Do not use /tmp to store data! /tmp is reserved for system use, it is not guaranteed to survive a reboot (here on Fedora it is backed by tmpfs, i.e., essentially a RAMdisk). /var/tmp is more stable (and designed for user use). Not ideal either. A directory under /home/user would be ideal. You might just have users run it in their home, and give e.g. proggie as the directory (and create it beforehand, if needed). Or perhaps $HOME/proggie works.
    – vonbrand
    Mar 8, 2016 at 19:52
  • @vonbrand I quite agree that /tmp is a bad place to store data. But it's not a bad place to write a downloaded file to, provided you later move it to wherever you'd like to actually store it.
    – Jenny D
    Mar 9, 2016 at 9:04
0

If ${HOME} doesn't work as suggested by Andy, you could try /proc/self/cwd/.

Or however you're configuring this path, just configure a different one for each user you distribute it to.

Or don't run the program directly, but run it in a script. The script could set the path however you are doing it now, or it could cd to the data dir, then run the program by path, and you can configure "." as the data dir.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .