如何以其他用户身份登录,然后以bash脚本注销?

Neu*_*ino 4 bash scripting

我需要编写一个bash脚本来作为另一个用户执行某些操作然后返回初始用户...

假设我以root身份运行以下命令:

#!/bin/bash
USER=zaraza
su - "${USER}"
#do some stuff as zaraza
________ #here I should logout zaraza
#continue doing things as root
Run Code Online (Sandbox Code Playgroud)

在控制台中我应该写"退出",但在bash中是一个关键字,它退出脚本...

提前致谢,

小智 5

使用su -c.从手册页:

 su man -c catman
        Runs the command catman as user man.  You will be asked for man's
        password unless your real UID is 0.
Run Code Online (Sandbox Code Playgroud)