Command
sudo su启动一个交互式根外壳程序,但不会将当前外壳程序转换为根外壳程序。
做您想要的事情的成语与此类似(感谢@CharlesDuffy的额外注意):
#check for rootUID=$(id -u)if [ x$UID != x0 ] then #Beware of how you compose the command printf -v cmd_str '%q ' "$0" "$@" exec sudo su -c "$cmd_str"fi#I am rootmkdir /opt/D3GO/#and the rest of your commands
这个想法是检查当前用户是否是root用户,如果不是,请使用以下命令重新运行同一命令
su



