Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 4 down vote accepted

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.

share|improve this answer
magic thanks. That explains it! – user4979 Feb 22 '11 at 16:40

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.

share|improve this answer

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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