I have the below script, it is meant to be run with sudo however the first to commands (The git commands) need to run as the user "ubuntu"

sudo -u ubuntu "git -C linux/build-repo pull"
sudo -u ubuntu "git -C android/build-repo pull"

uoa_image=$(sh linux/build-repo/make.sh | sed -n '1 p')

echo $uoa_image

However when this is run with sudo, the first two commands fail and the make.sh script when runs complains it doesn't have root

First lines give the errors:

sudo: git -C linux/build-repo pull: command not found
sudo: git -C android/build-repo pull: command not found 
  • You should not build software as root. If there are reasons that you need to then a fakeroot will probably help. – ctrl-alt-delor Sep 28 '15 at 22:01

One option:

Run the whole script as sudo-to-root and change the first two lines to use su instead:

su -c "git -C linux/build-repo pull" ubuntu
su -c "git -C android/build-repo pull" ubuntu

A second option:

set up root's PATH so that it can find the git command.

  • this fixes the git commands however the script still runs as if it doesn't have root – Zac Powell Sep 28 '15 at 20:44
  • @richard has a good point in his answer; as to your comment: did you run it as root? – Jeff Schaller Sep 28 '15 at 22:00

The error messages are because of the quotes: you need

sudo -u ubuntu git -C linux/build-repo pull


sudo -u ubuntu "git -C linux/build-repo pull"

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.