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;
  • 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

$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}')"
  • @tijko getent returns colon separated lines, so $6 would be the sixth element, which is your home directory
    – daisy
    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 ...
    – daisy
    Mar 3 '13 at 23:58

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.