在忙碌的日子里,我想跑步
$ ./configure && make && sudo make install && halt
Run Code Online (Sandbox Code Playgroud)
晚上睡觉,希望应用程序会自动安装。但是第二天我看到的是 sudo 要求我输入密码的屏幕。那么我怎么能在一个命令行中使用密码运行 sudo ,或者有没有其他方法可以做到这一点?
有没有办法在脚本中切换用户身份(作为安装过程的一部分以 root 身份执行)以执行某些命令而不调用外部脚本,然后返回root运行其他命令?
有点:
#!/bin/bash
some commands as root
SWITCH_USER_TO user
some commands as user including environment variables checks, without calling an external script
SWITCH_USER_BACK
some other stuff as root, maybe another user id change...
Run Code Online (Sandbox Code Playgroud)