Difference between su oracle and su - oracle? Difference between su oracle and su - oracle? unix unix

Difference between su oracle and su - oracle?


According to the man page

 -l      Simulate a full login.  The environment is discarded except for HOME, SHELL, PATH, TERM, and USER.  HOME and SHELL are modified as above.         USER is set to the target login.  PATH is set to ``/bin:/usr/bin''.  TERM is imported from your current environment.  The invoked shell is         the target login's, and su will change directory to the target login's home directory. -       (no letter) The same as -l.

In a nutshell, if you use su - oracle you switch to the user oracle and the environment is reset. Without -, the environment is not reset.

For example, without - :

#(root) export HELLO=world#(root) su postgres$(postgres) echo $HELLOworld$(postgres)

And with - :

#(root) export HELLO=world#(root) su - postgres$(postgres) echo $HELLO$(postgres)


su - oracle it starts a login shell so the oracle user environment is used. W/O the hyphen just changes to the user oracle user; this grants the same rights as the oracle user so you can have access to files/directories owned by oracle.