There is a shell script (/ bin / sh, not bash) that requires root privileges to execute.
If it is started as a normal user, it must ask the user for a password to gain root access and restart.
Now it uses the following code:
if [ $(id -u) -ne 0 ]; then su root -- $0 $@ ; ... fi
This works well, but there are some OSs like Ubuntu that don't have a root password. On the other hand, many systems use sudo as root.
Question: how can a script determine whether to use
su or
sudo without asking the user to enter too many passwords (for example, enter
sudo password, if it does not work, run
su )).
linux shell su sudo
zserge
source share