Switch Desktop Environments via Terminal

Hi All,

Does anyone know if it's possible to switch desktop environments via the terminal?

I'm writing a script to install Cinnamon on Ubuntu and I would then like to remove unity but at the moment I have to ask the user to log out, log in with cinnamon and then continue the script to remove unity.

Often a desktop is just an X windows manager on steroids, so if you kill one WM and start another, you get a modified desktop, but the X connections and X server keep running. In the middle everything loses windows frames. It often pays to then kill that terminal, so keyboard SIGINT like cntrl-C does not kill the WM in the same terminal group.