From: Peter Hanke on
Assume I am currently logged in as user "karl" in a terminal with current path

/tmp/

Now I do a "su" and enter the root password.

This causes the terminal to switch to user "root" and - unfortunately - to a different directory
e.g. /home/root

Ok, I can do now a

cd /tmp

to get to the other directory.

but I could imagine that there is a way to tell Unix to stay automatically (!) in the
directory where the original "su" command was issued.

How can I achieve this?

Peter

From: Chris F.A. Johnson on
On 2010-07-18, Peter Hanke wrote:
> Assume I am currently logged in as user "karl" in a terminal with current path
>
> /tmp/
>
> Now I do a "su" and enter the root password.
>
> This causes the terminal to switch to user "root" and - unfortunately - to a different directory
> e.g. /home/root
>
> Ok, I can do now a
>
> cd /tmp
>
> to get to the other directory.
>
> but I could imagine that there is a way to tell Unix to stay automatically (!) in the
> directory where the original "su" command was issued.
>
> How can I achieve this?

'su' does not change directories; it will leave you in the same
directory.

'su -' will behave as a login and will change directories.

--
Chris F.A. Johnson, <http://cfajohnson.com>
Author:
Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
From: unruh on
On 2010-07-18, Peter Hanke <peter_ha(a)andres.net> wrote:
> Assume I am currently logged in as user "karl" in a terminal with current path
>
> /tmp/
>
> Now I do a "su" and enter the root password.
>
> This causes the terminal to switch to user "root" and - unfortunately - to a different directory
> e.g. /home/root

Nope. It does not. It leaves the directory alone. Now if you do
su -
then it will change directory.

>
> Ok, I can do now a
>
> cd /tmp
>
> to get to the other directory.
>
> but I could imagine that there is a way to tell Unix to stay automatically (!) in the
> directory where the original "su" command was issued.
>
> How can I achieve this?
>
> Peter
>