I need to copy-paste a bunch of shell commands to emacs and run them as
sudo. How do I do it?
For instance, while configuring samba, I come across this instruction from the documentation:
mkdir /usr/local/samba/lib/usershares chgrp foo /usr/local/samba/lib/usershares chmod 1770 /usr/local/samba/lib/usershares
I would like to paste the commands to a scratch buffer and run. If they don't require
sudo, then I can use
shell-command-on-region (M-|). But how do I execute these lines as root?
sudo to lines fail with
sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper.
-S flag to
sudo makes the command fail without asking for password.
As an another approch, I switched the
*scratch* buffer to
shell-script-mode, selected the region and
Execute region C-M-x. This works great for non-sudo commands, but fails with the same message as above.