How to replace my username in a script with variable
Solution 1:
You can use the variable $HOME
for the home, and $USER
for the user.
Your example can then be $HOME/Downloads
or /home/$USER/Downloads
.
Solution 2:
If you want to do this you should use ...
more ~/.config/user-dirs.dirs
# This file is written by xdg-user-dirs-update
# If you want to change or add directories, just edit the line you're
# interested in. All local changes will be retained on the next run
# Format is XDG_xxx_DIR="$HOME/yyy", where yyy is a shell-escaped
# homedir-relative path, or XDG_xxx_DIR="/yyy", where /yyy is an
# absolute path. No other format is supported.
#
XDG_DESKTOP_DIR="/discworld/Desktop"
XDG_DOWNLOAD_DIR="/discworld/Downloads"
XDG_TEMPLATES_DIR="/discworld/Templates"
XDG_PUBLICSHARE_DIR="/discworld/Public"
XDG_DOCUMENTS_DIR="/discworld/Documents"
XDG_MUSIC_DIR="/discworld/Music"
XDG_PICTURES_DIR="/discworld/Pictures"
XDG_VIDEOS_DIR="/discworld/Videos"
so that would be
echo $(xdg-user-dir DOWNLOAD)
and it will show the default download location (in my case /discworld/Downloads
). Works for all of these words. Like ...
echo $(xdg-user-dir DESKTOP)