The su
command has a number of options that can be used to modify its behavior. One of these options is -
, which stands for “login shell”. When the -
option is used with the su
command, it causes the su command to run a login shell for the specified user. This means that the user’s environment variables and profile scripts will be sourced as if they had logged in to the system normally.
For example, to switch to the root user and run a login shell, you would use the following command:
Check for the system environment after switching to the root user.
On the other hand, if you omit the -
option and just use the su
command by itself, it will switch to the specified user without running a login shell. This means that the user’s environment variables and profile scripts will not be sourced, and the user will be in the same environment as before they switched users.
For example, to switch to the root user without running a login shell, you would use the following command:
See the system environment after switching to the root user.
In summary, the difference between su
and su -
is that su
switches to the specified user without running a login shell, while su -
switches to the specified user and runs a login shell. It’s important to understand this difference, as it can affect the environment in which you are working when switching to a different user account.