I create an alias as my current user in the bash shell, which I can see using the alias command.

When I switch user without the -, i.e. su testuser, the alias is not carried into the new user's environment.

Any idea why?


This is because su creates a new shell, starting fresh. So if you want your alias to persist, you need to create it in your .bashrc.


From man su:

The optional argument - may be used to provide an environment similar
to what the user would expect had the user logged in directly.

As asoundmove and Barun explained, su starts a new shell, so without the - it is like running bash --norc.


Thing is, when you create any alias in the terminal, it is temporary. If you open another terminal while you are logged in as the same user, you won't be able to access that alias. So, you need to store them permanently, as said by asoundmove, in .bashrc file. You can store it in any other file also, but then that has to be included in your .bashrc file.

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.