Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm writing a bash-script that will be run as a cron job everyday. Very basic, I was wanting to change the wallpaper daily. I have mint-14 with mate.

The thing I'm getting caught up on right now is, I want to have the user's home path detected automatically. If I don't do this I would have to change it for all other users that run the script.

So far I have tried:


mateconftool-2 -t string -s /desktop/mate/background/picture_filename $homedir;

This doesn't work but,

echo $homedir

Prints out the correct path?


When I tried ~user like @vonbrand was suggesting there is no difference.

mateconftool-2 -t string -s /desktop/mate/background/picture_filename ~user/Pictures/daily;
share|improve this question
At least csh, bash use ~user for the user's home. It is the value of the shell variable HOME for each user. – vonbrand Mar 3 '13 at 0:00
I've tried to change the above script example to use ~user with the mateconftool-2 command but, its not working? I've edited my post to reflect this. – tijko Mar 3 '13 at 0:49
up vote 5 down vote accepted

$HOME is not set in cron, so put this in a script, and let your cron job execute that instead,

(Remember to set the execution bit for that script with chmod +x XX)


mateconftool-2 -t string -s /desktop/mate/background/picture_filename ~/Pictures/daily

Or in your cronjob,

HOME="$(getent passwd $USER | awk -F ':' '{print $6}')"
share|improve this answer
@tijko getent returns colon separated lines, so $6 would be the sixth element, which is your home directory – warl0ck Mar 3 '13 at 1:18
Honest question: how portable is it? Is it safe to assume that the user's home directory is the 6th element of the /etc/password file for several (most) unices? – rahmu Mar 3 '13 at 23:23
@rahmu hmm, I'm not sure, but the OP runs mint, so that's okay here ... – warl0ck Mar 3 '13 at 23:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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