Using expect under gnome i login as root:

expect -c 'spawn su - ;expect senord:;send "assword";interact'

but opening a GUI-application doesn't work:


spawn su -
Lösenord:
root@x22:~# nautilus


(org.gnome.Nautilus:50916): Gtk-WARNING **: 13:56:46.709: cannot open display:
root@x22:~#

Doing the same using su insted of expect works OK.
Why is this so?
My system is Ubuntu 22.04 on an Intel i7.