How can i get the path to the given users desktop?
I used this:
echo $(awk "NR==$(awk 'BEGIN {FS=":"} {print $3}' /etc/passwd | awk "/^$(id -u USERSNAMEHERE)$/ {print NR}")" /etc/passwd | awk 'BEGIN {FS=":"} {print $6}')/Desktop
are there any better ones?
What if the users Desktop's name isn't "Desktop"?
Thank you!
p.s.: using Fedora 14 but are there any "general" methods to find out the given users desktop?
Try xdg-user-dirs.
That page has an example that should work for the current user:
Also, if you have to read
/etc/passwd
, it's better to use the output ofgetent passwd
, because some user data might be stored in NIS, LDAP, or some other database.Combining that so it works for a user called
USERSNAMEHERE
:Your command is impossibly complex.
Here is a simplified version:
Here is an untangled version of your original:
or
The
xdg-user-dir
utility can help you:It only works like this if you're logged as the user though. You can fool it by specifying
XDG_CONFIG_HOME
:If you look at the script itself, it roughly does the same thing as the snippet in Mikel's answer.
the path is
$HOME/Desktop
test by
echo hello > $HOME/Desktop/testing.txt
You're making it way more complex than it has to be.
~UserName
is an alias for UserName's home directory.Use
~UserName/Desktop
.