how to run two commands in sudo? how to run two commands in sudo? bash bash

how to run two commands in sudo?


For your command you also could refer to the following example:

sudo sh -c 'whoami; whoami'


sudo can run multiple commands via a shell, for example:

$ sudo -s -- 'whoami; whoami'rootroot

Your command would be something like:

sudo -u db2inst1 -s -- "db2 connect to ttt; db2 UPDATE CONTACT SET EMAIL_ADDRESS = 'mytestaccount@gmail.com'"

If your sudo version doesn't work with semicolons with -s (apparently, it doesn't if compiled with certain options), you can use

sudo -- sh -c 'whoami; whoami'

instead, which basically does the same thing but makes you name the shell explicitly.


I usually do:

sudo bash -c 'whoami; whoami'