How can I execute a series of commands in a bash subshell as another user using sudo?

后端 未结 6 888
别跟我提以往
别跟我提以往 2021-01-30 10:33

I\'m writing a bash script that needs to sudo multiple commands. I can do this:

( whoami ; whoami )

but I can\'t do this:

sudo          


        
6条回答
  •  日久生厌
    2021-01-30 11:22

    The Brackets means that execute the command in a new bash.It execute the command with the interval of semicolon.Just use the code below instead.

    (sudo whoami;sudo whoami)
    

    BYW:the space is not necessary when using '()'.

提交回复
热议问题