I'm writing a script to copy my display settings from my user to root, to avoid the X11 problem when running GUIs as sudo (ex. vivado install on remote machine)
the thing is that this works:
sudo xauth add $(xauth -f ~theuser/.Xauthority list|tail -1)
and this:
xauth -f ~theuser/.Xauthority list|tail -1
has the output:
servername/unix:12 MIT-MAGIC-COOKIE-1 1ec6eb59738a492928b63451d2c63304
But, and here is my problem, I want to create a script so this can be done by any user
x11sudo.sh
currentUser=$(whoami)
sudo xauth add $(xauth -f ~$currentUser/.Xauthority list|tail -1)
but doesn't work.
The issue is in xauth -f ~$currentUser/.Xauthority list|tail -1
not recognizing the path to .Xauthority
if in the command line I write:
theuser@servername:~ $ currentUser=$(whoami)
theuser@servername:~ $ echo $currentUser
theuser
theuser@servername:~ $ xauth -f ~$currentUser/.Xauthority list|tail -1
xauth: error in locking authority file ~theuser/.Xauthority
theuser@servername:~ $
I've tried some iterations, adding echo
, ""
, ''
and others but always the same result, it doesn't like the text string ~theuser/.Xauthority
if it's created with a variable.
Thank you very much