Sudo: menjalankan command di script

From OnnoWiki
Revision as of 21:03, 16 December 2018 by Onnowpurbo (talk | contribs) (Created page with "sumber: https://askubuntu.com/questions/425754/how-do-i-run-a-sudo-command-inside-a-script It is rarely a good idea to have sudo inside scripts. Instead, remove the sudo f...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

sumber: https://askubuntu.com/questions/425754/how-do-i-run-a-sudo-command-inside-a-script



It is rarely a good idea to have sudo inside scripts. Instead, remove the sudo from the script and run the script itself with sudo:

sudo myscript.sh

That way, all commands within the script will be run with root privileges and you only need to give the password once when launching the script. If you need a particular command within the script to be run without sudo privileges, you can run it as a regular user with (thanks Lie Ryan):

sudo -u username command 

The space is irrelevant, it should not affect anything, there is always a space between a command and its arguments.


Referensi