Execute single command in shell script without sudo

后端 未结 2 1004
梦谈多话
梦谈多话 2021-01-11 12:12

I have a simple shell script that is run with sudo as most of the script requires it, yet one of the commands in the script is a Homebrew install, which cannot be executed w

2条回答
  •  鱼传尺愫
    2021-01-11 12:43

    The easiest way is to run the subcommand via sudo from within the script. The user id to run with can be obtained by $SUDO_USER (look at the output of sudo env):

    sudo -u $SUDO_USER ./exec_as_normal_user.sh
    

提交回复
热议问题