In both cases, once you leave the subshell this is reverted back because all the changes are made within that subshell. With the dash, though, your environment is completely overwritten by the environment of the new user, effectively it is like doing a login as the new user - complete with executing the profile and whatever else is done during a normal login. Variables like "PATH" and everything else you have set remains even though the user credentials change. Let us first talk about the difference between the first and the second: without the dash ("-") in between the environment of your own user is preserved. Notice that there are two (three) ways to run su: What su does is to open a subshell (you are correct in your assumption that it does) with the new rights and you are that new user as long as you do not leave this shell again. Now, everybody can - in principle - use the command su to switch the user. This is why only root (or sometimes a special user group "wheel") is allowed to do it. ![]() You don't want any of them to shut down the system whenever they feel like it in such a setting. UNIX is a multiuser system at its core so the "default use case" it was built with in mind is some dozens of users using the same system at the same time. My user account on MacOS is administrator, but sudo appears frequently and apparently shutdown is one of the tasks that requires password authentication.įirst, yes, the shutdown command can only be issued by the root user. This does not happen under Windows or Linux, I guess because I am running from an account with administrator. In MacOS, the backup works correctly, but I get an error from the shutdown command that I am not super user. I can add a command to switch to super user, sudo su, so that when the user specifies that they want to shutdown they can enter their password (you have to use sudo to switch to su in MacOS, more or less). My user account on MacOS is administrator, but sudo appears frequently and apparently shutdown is one of the tasks that requires password authentication. This works well on Linux and Windows cygwin. # prompt to exit script if not shutting down ![]() Code : #!/bin/bash # read input to shutdown after script or notĮcho "do you want to shutdown after the backup is finished? (y/n) "
0 Comments
Leave a Reply. |