The difference between switching users su and su in Linux Shell

  
 

encountered such a problem in the Linux Shell, run a shell under the Oracle user, you need to switch to another user (load) during the run, delete some files of the user.

The general idea is as follows (part of the shell script):

passwd=load

su – load <<!

$passwd

cd ~/backup

rm *.txt

exit

!

By the way, the difference between su and su – >

‍ The former just switched the identity, but the SHELL environment is still the original user's SHELL; www.linuxidc.com and the latter switched to the new user with the user and the SHELL environment. The PATH environment variable error does not occur only when the SHELL environment is switched. Specific case:

Someone used root to log in. Then switch to the oracle user, execute the sqlplus command but report an error: ‍command not found!

Because you are using su instead of su - there is another obvious difference:

For example, the root user is in the /root/directory, su oracle,

switched to the oracle user, but the directory is still under /root/.

If you use su – oracle

you can find that the directory is also switched to the oracle user's home directory.

Copyright © Windows knowledge All Rights Reserved