Shell – How to detect if DE is Unity or XFCE via shell script

desktop-environmentshell-script

I have a few configuration scripts that I run everytime I install a fresh version of Ubuntu. Recently, however, I migrated to Xubuntu. I would like to use the same script for both distros, since both of them are very similar, but I would also like some parts of the script to be executed only under Xubuntu, and others only under Ubuntu.

My question is: is there a way to tell these distros apart via shell script?

I tried using the lsb-release application, but it seems to not be implemented under Xubuntu; I also tried to read the contents of /etc/*-release, but the contents seem to be similar in both distros.

$ lsb_release 
No LSB modules are available.
$ cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=15.04
DISTRIB_CODENAME=vivid
DISTRIB_DESCRIPTION="Ubuntu 15.04"

Best Answer

It's impossible to tell Xubuntu from Ubuntu, because they are the same distribution. Xubuntu and Ubuntu are two different installers which set up different desktop environments, but after the initial installation, the administrator can install additional desktop environments. Users can run XFCE after an initial Ubuntu installation or Unity after an initial XFCE installation.

If you wanted to set up some things differently depending on the desktop environment, this is a per-user setting, not a global setting. Since users can run different desktop environments at different times, you should prepare for both (and for KDE, and for twm, etc.).

Related Question