If I call a bash script with sudo, for example:

sudo bash script.sh

Do I still have to use sudo inside the script in cases like this:

sudo apt-get update

link|improve this question
2  
Did you try it? – Cfreak Aug 9 '11 at 19:15
Course. I am getting a strange error: "+ sudo chmod +x /usr/bin/apt-fast =>> cleanstart.sh: line 134: sudo: command not found" that's why I did this basic question. – Roger Aug 9 '11 at 19:33
That's odd. The error message seems to indicate that sudo can't find the chmod command. Unless the command in the script is sudo "chmod +x /usr/bin/apt-fast", which would cause sudo to look for a command named "chmod +x /usr/bin/apt-fast". (But in any case, you don't need sudo inside the script.) – Keith Thompson Aug 9 '11 at 19:49
I see from your other question that your script had clobbered $PATH. – Keith Thompson Aug 9 '11 at 20:30
feedback

migrated from stackoverflow.com Aug 9 '11 at 21:52

This question came from our site for professional and enthusiast programmers.

2 Answers

up vote 3 down vote accepted

No. the command will be run with root privileges and all commands that the script runs will inherit the privileges.

link|improve this answer
feedback

no, by calling sudo you are running a process in kernal mode which means you have access to everything, you no longer have to use special permissions in different areas of your code/script.

link|improve this answer
You're not running in any sort of "kernel mode". You're just running it as a user with elevated permissions. – Wuffers Aug 21 '11 at 2:35
feedback

Your Answer

 
or
required, but never shown

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