# Verify Linux Desktop Environment ## Introduction In the event that you need to quickly determine if your Linux [desktop environment](https://en.wikipedia.org/wiki/Desktop_environment) is utilizing either [X11](https://en.wikipedia.org/wiki/X_Window_System) or [Wayland](https://en.wikipedia.org/wiki/Wayland_(protocol)), we may utilize a simple [Bash](https://en.wikipedia.org/wiki/Bash_(Unix_shell)) command to output the current desktop display server. This guide explores different options to identify the display server protocol your session is running. ### Prerequisites - [ ] [Terminal](https://en.wikipedia.org/wiki/Terminal_emulator) --- ## Command This Bash command uses [`printf`](https://en.wikipedia.org/wiki/Printf_(Unix)) to output a message that specifies which display server protocol (X11 or Wayland) the session is running: ```sh printf 'Session is: %s\n' "${DISPLAY:+X11}${WAYLAND_DISPLAY:+WAYLAND}" ``` > [!example] > ![[check-desktop-environment-terminal.png]] ### Breakdown | Command | Definition | | -------------------------------------------: | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `printf 'Session is: %s\n'` | A standard output command with a format string: a placeholder `%s` for inserting a value and `/n` to start a new line at the end. | | `${DISPLAY:+X11}` | This is a _parameter expansion_ that checks if the environment variable `DISPLAY` is set. If `DISPLAY` is non-empty (meaning X11 is in use), it expands to `X11`. If `DISPLAY` is unset or empty, it expands to an empty string (`""`). | | `${WAYLAND_DISPLAY:+WAYLAND}` | A _parameter expansion_ that checks if the environment variable `WAYLAND_DISPLAY` is set. If `WAYLAND_DISPLAY` is non-empty (indicating a Wayland session), it expands to `WAYLAND`. If `WAYLAND_DISPLAY` is unset or empty, it expands to an empty string (`""`). | | `${DISPLAY:+X11}${WAYLAND_DISPLAY:+WAYLAND}` | Two expansions, concatenated without spaces. This means that if: `DISPLAY` is set, `printf` will output "Session is: X11". `WAYLAND_DISPLAY` is set, it will output "Session is: WAYLAND". | ### Alias **Manual Setup** We may create a Bash [alias](https://en.wikipedia.org/wiki/Alias_%28command%29), easily referenced as `de` for 'desktop environment', by following the steps below. 1. Open the aliases file via: ```sh nano ~/.bash_aliases ``` 2. Add the following `de` alias on a new line: ```sh alias de='printf "Session is: %s\n" "${DISPLAY:+X11}${WAYLAND_DISPLAY:+WAYLAND}"' ``` 3. Save and exit the aliases file. 4. Reload the aliases file via: ```sh source ~/.bash_aliases ``` > [!done] > Verify our new desktop environment alias works via the newly created `de` command. **Automatic Setup** If you prefer a more simplistic alias setup, the following command will automatically add a `de` alias to the bottom of your aliases file: ```sh echo 'alias de='"'"'printf "Session is: %s\n" "${DISPLAY:+X11}${WAYLAND_DISPLAY:+WAYLAND}"'"'"'' >> ~/.bash_aliases && . ~/.bash_aliases ``` --- # Conclusion > [!note] > _Comments, corrections, and/or suggestions?_ [[Contact]] me and I'll happily accredit your contribution.