I'm working on some installation script in bash (on a Raspberry Pi running Stretch). It will copy files to /usr/local/bin
and to my user profile and it will install a few packages if needed. The script is almost 2000 lines and 20–30 commands need root.
Now my question is: should I run the entire script with sudo
or just as standard user and sudo only the commands inside the script that need admin rights?
Best Answer
If you know for sure that running the script with
sudo
won't do you any harm (For example, it won't create new files that will now needroot
privileges, but wouldn't otherwise), you should run it withsudo
.If you know there are some side effects or you are unsure, do it the safe way and use
sudo
just where you must.