I am using arch linux with xmonad, and I login using gdm, but to make xmonad work properly I have to run a script directly after login (actually I want to run .xinitrc after login using gdm to set some configuration).so, How it is possible ro run a bash script immediatly after login.

I tried several ways such as editing


thank you,


To execute a script/command after you log in you can use ~/.bash_profile or ~/.bash_login. This method should normally be agnostic of how you logged in (e.g. whether you did a terminal login or logged in through a display/login manager). There's also ~/.bash_logout for commands after you log off.


# ~/.bash_profile

[[ -f ~/.bashrc ]] && . ~/.bashrc

exec startx

Should work to start X and execute .xinitrc as soon as you log in.

Please refer to the arch wiki for more info if you run into problems.

  • According to arch wiki I have to use ~./bashrc, but it did not function properly, after running it, I will not be able to open the terminal – husseinhoudrouge Jul 18 '16 at 20:22
  • yes that's right, it applies on every login... Do you need to open the terminal? Can't you just use your GUI terminal in X? – Cestarian Jul 20 '16 at 19:15
  • I am using gnome terminal and X terminal – husseinhoudrouge Jul 20 '16 at 19:16
  • Yes those will work fine since you have already logged in (.bash_profile is only applied when you log in, not after you have already logged in. So basically for this to happen again you'd have to press CTRL+ALT+F2 to go to tty2 and log in again and that would run .bash_profile again) – Cestarian Jul 20 '16 at 19:19
  • Do you think appending & at the the end of each line in .xinitrc can cause this problem – husseinhoudrouge Jul 20 '16 at 19:25

Most display managers will, upon successful login, look for and source a file called ~/.xsession. This is where you put your X session customisations, much as you put your shell customisations in, for example, ~/.bash_profile or ~/.zprofile

Note that the file ~/.xinitrc is sourced by startx, and not by default by display managers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.