Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
add comment

3 Answers

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
add comment

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
add comment

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
add comment

Your Answer

 
discard

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.