The shell can expand ~ to your home directory. $HOME usually has the same deal, but often you want to refer to the current users home directory from a context that may not support such expansion.

I have had config files where $HOME works but ~ doesn't and vice versa.

I would guess that fuse could provide something along these lines, something like /var/myself -> $HOME

With that I could place values in config files to point to things like /var/myself/backdrops/pornography/wtf/yarly.jpg

Is there something like this already? If not, are there good reasons for there not being something like this?

  • 2
    This actually seems like a really good idea, and fuse could do this pretty trivially if I remember the interface correctly – Michael Mrozek Sep 9 '10 at 6:54

I understand your concern but the answer is "no" there is not such thing.
The usual method is to ask the OS the user's home path, or get the $HOME variable.

All these options needs always some coding from the application. A lot of applications, like bash, offer the "alias" ~ (open(2) does not translate that).

Of course a vfs or a fuse module could be implemented to do this. Probably there is something to do that, I am going to ask that!

But is it really needed? You can use a workaround like:


One trick (on Linux, at least) would be to change directory to $HOME before running the app and then use /proc/self/cwd/... in the config file.

  • I like the hackishness of this but presumably it would run into problems it the process changes the current directory. I'd like a /proc/PID/iwd for initial working directory. – Lerc Sep 12 '10 at 11:26
  • ...and for that matter a /proc/PID/home – Lerc Sep 12 '10 at 11:32
  • @Lerc, if it's going in a config file it needs to be /proc/self not /proc/PID, since you can't know in advance what the PID is going to be. – Neil Mayhew Sep 12 '10 at 13:53
  • @Lerc, yes, if the process changes directory then it would fail, but typically programs read the config file once when they start up, and then cache the values in memory. It all depends on the program you are working with, and if the program doesn't offer enough flexibility, either on the command line or in the config file syntax, then you are stuck. – Neil Mayhew Sep 12 '10 at 13:56
  • Yeah, I meant /proc/PID/home to mean that all proc/PID dirs should support this and thus include /proc/self – Lerc Sep 13 '10 at 11:09

Most programs allow you to specify a path to the configuration file on the command line. So you could write a wrapper that takes a standard configuration file, filters it to substitute things like $HOME for the current user, and then passes the modified, temporary configuration file to the program.

  • If you do that then you've effectively taken the ability to specify a path to the config file away from the user. Might be doable if you get rally fancy with a wrapper exe. – Lerc Sep 13 '10 at 11:08

You can get the pid of requestin user and ask system of his/her home directory. So it is possible.

However I'm not sure if there is no SUID programs that would assume FS as static.


struct fuse_context *ctx = fuse_get_context ();
struct passwd pwd, *ppwd;
char buffer[1024];
int status = getpwuid_r (ctx->ui, &pwd, buffer, sizeof(buffer), &ppwd);
if (status == 0) {
  if (ppwd == NULL) {
    // No record found
  } else {
    // Handle record
} else {
    // Handle error

The above code is not ideal but should do work for common cases.

  • How would you find his home directory after you know what user it is? – WhyNotHugo Sep 12 '10 at 18:47
  • Using getpwuid or getpwuid_r. – Maciej Piechotka Sep 12 '10 at 20:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.