-1

I have a script install.sh which contains commands to install packages on ubuntu. For ex:

#/bin/bash

sudo apt-get update 
sudo apt-get updgrade
sudo apt-get install <package>

Now there is a command which I want to run without sudo so I'll write without sudo

#/bin/bash

sudo apt-get update 
sudo apt-get updgrade
sudo apt-get install <package>
pcmanfm --set-wallpaper /path to file  <-- I want this to be run without sudo

But when I run the script, I do sudo sh install.sh which automatically makes all the commands to be executed as sudo. Is there anyway, I can protect pcmanfm command to not to run as sudo.

2

You should execute the script in the following way:

./install.sh

or

sh ./install.sh

This will cause that only command which start with sudo in the script will run as a root.

Note that the ./ prefix for the install.sh means that the install.sh from the current directory will be executed.

  • Yes but for some reason, I need to use sudo for install.sh – S Andrew Jul 27 '17 at 6:58
  • 3
    The script execute sudo for the commands inside which requires to be executed by root. why do you need to execute the entire script as root using sudo? – Yaron Jul 27 '17 at 6:59

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.