Is it considered good or bad practice to use the sudo command inside a shell script? One advantage is that if the user runs the script as non-root, she or he will be asked for password on demand rather than the script failing. On the other hand, if the user has recently run a command with sudo, the script will implicitly run commands as root which may not be what the user expects.
Here is an example:
$ cat foo1 #!/bin/sh sudo bar #implicit sudo $ ./foo1 $ cat foo2 #!/bin/sh bar $ sudo ./foo2 #explicit sudo