Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm working on an installer script for the latest ATI drivers (as they are not in repo) and was wondering if I need to include sudo in the script, because it will be needed for the install.

share|improve this question

2 Answers 2

up vote 3 down vote accepted

no, if you need root privileges you call the script with sudo.

share|improve this answer
    
Thanks, I wasn't sure, and wanted to check before testing it :D –  Chris Weigle Jan 8 '12 at 6:11
    
@ChrisWeigle: In general, this is correct. However, there might be cases where you want sudo in the script itself. How well this works depends on your sudo configuration, since sudo might or might ask for a password. The case I most commonly use is for editing text files. I use vim, which I call vi out of longstanding habit. On my system, vi is actually a script that runs sudo vim if the file isn't otherwise writeable. (By the way, such a script is for experienced users only, as you can break your system with it if you aren't careful.) –  Scott Severance Jan 8 '12 at 22:53
    
I understand Scott, but, you probably also realize, as an experienced user, that is a dangerous script indeed ;) –  bodhi.zazen Mar 19 '13 at 0:25

All commands in a script are run as the calling user. So if I write this script:

/home/user/my_script

#!/bin/bash
echo "I am running as root" > /root/status.txt

I can successfully produce a file containing "I am running as root" at /root/status.txt by executing either:

user@host$ sudo /home/user/my_script

Or as the superuser:

root@host$ /home/user/my_script
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.