Command sudo su
启动一个交互式根外壳程序,但不会将当前外壳程序转换为根外壳程序。
做您想要的事情的成语与此类似(感谢@CharlesDuffy的额外注意):
#check for root
UID=$(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 root
mkdir /opt/D3GO/
#and the rest of your commands