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

  • 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
  • 1
    I see from your other question that your script had clobbered $PATH. – Keith Thompson Aug 9 '11 at 20:30

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


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.

  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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