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
su testuser, the alias is not carried into the new user's environment.
Any idea why?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
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
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
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