Search code examples
bashshellsu

Execute command if su to a certain user


If I enter sudo su - Rorschach and login as Rorscach. I would like a command to be executed automatically.

Such as echo "Hello Rorschach" or cd ~

Where do I put these scripts in order for them to be performed upon login of that user?

I am using an ubuntu 14.04 command line and echo $0 outputs -bash


Solution

  • ~/.bash_profile (recommended) or ~/.bashrc (will work, but this file should rather contain functions and aliases, not commands).