exec builtin replaces the shell by the specified program. After that point, the shell is no longer around to load
In any case, the shell that runs
.xinitrc is not a login shell, so it wouldn't run any
.*logout file — but that shell is not where you would run
startx anyway, it's a file that's loaded from
xinit which is executed by
If you want to run something after logging out of the graphical session, you need to keep the shell running and specify something to run after
startx. Assuming that the
exec startx line is in
.profile or a similar file executed by your login shell, you need to keep the shell running while the X session is active, then
exit (so as not to follow the GUI session by an interactive shell).
if [[ -z $DISPLAY && $XDG_VTNR -le 4 ]]; then
if startx; then
# We just exited an X session.
# If your login shell is bash, it runs ~/.logout at this point.
echo >&2 "The X session aborted with an error, dropping to a text shell"