Depending upon how much control you have over the environment, it's possible to configure a namespace that behaves in a way that's similar to what you want. Here's a script that does this:
#!/bin/bash
if [ "$(id -u)" -ne "0" ]; then
FAKEROOT=$(mktemp -d --tmpdir "fakeroot.XXXXXXXXXX")
unshare -Urm "$0" "${FAKEROOT}"
rm -rf "${FAKEROOT}"
exit 0
fi
FAKEROOT="$1"
mkdir -p "${FAKEROOT}/old_root"
for FILE in $(ls /); do ln -s "/${FILE}" "${FAKEROOT}/old_root/${FILE}"; done
for FILE in $(ls /); do ln -s "old_root/${FILE}" "${FAKEROOT}/${FILE}"; done
mount --bind "${FAKEROOT}" "${FAKEROOT}"
pivot_root "${FAKEROOT}" "${FAKEROOT}/old_root"
/bin/bash --init-file <(echo '. ~/.bashrc; symvar() { VAR=$(echo "$1" | sed "s/=.*//"); TGT=$(echo "$1" | sed "s/[^=]*=//"); ln -sf "${TGT}" "/\${${VAR}}"; }')
At this point you can then define a symlink variable with the BSD syntax:
symvar HOME=/home/your-username
and you can create symlinks that look like this:
ln -s '/${HOME}/Desktop' 'Desktop Folder'
If you combine this solution with the "revertuid" solution code* then you can include something like this in the default script:
symvar HOME="${HOME}"
example (replacing the last line in the script):
revertuid /bin/bash --init-file <(echo '. ~/.bashrc; symvar() { VAR=$(echo "$1" | sed "s/=.*//"); TGT=$(echo "$1" | sed "s/[^=]*=//"); ln -sf "${TGT}" "/\${${VAR}}"; }; symvar HOME="${HOME}";')
- Note: if any of your user ids are not 1000 then you will need to tweak the revertuid example code. All you would need to do is to pass the UID to the subscript and hand that to revertuid as the first argument.
~
.$HOME
is always going to get resolved the moment I create the link (isn't it?), and is therefore going to be machine-dependent.