有没有一种方法可以在脚本内切换用户身份(在安装过程中作为根用户执行),以执行某些命令而无需调用外部脚本,然后返回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...
                  我如何使用su以该用户身份执行bash脚本的其余部分的
                
                
                  
                    —
                    Dan Dascalescu 2014年
                    
                  
                
              
                  您应该看看这个答案stackoverflow.com/a/17758312/1243547
                
                
                  
                    —
                    Klaus