1

In a shell script that's using curl to fetch a script, then executing it, are these two approaches materially different?

curl http://address-to-some-script/dosomething.sh | sudo tee /usr/bin/dosomething.sh

...vs...

sudo curl http://address-to-some-script/dosomething.sh >> /usr/bin/dosomething.sh

There's something about the sudo right before curl in the second command that's giving me pause, but I can't articulate whether or how it's different (riskier?) than the first.

  • 1
    There is never a reason to run curl with sudo. – Kusalananda Jan 22 at 18:01
7

There are a number of material differences.

curl http://address-to-some-script/dosomething.sh | sudo tee /usr/bin/dosomething.sh

runs curl as the current user, and tee as root; it also clears the contents of /usr/bin/dosomething.sh before writing to it.

sudo curl http://address-to-some-script/dosomething.sh >> /usr/bin/dosomething.sh

runs curl as root, and tries to append to /usr/bin/dosomething.sh with the permissions of the current user (the current shell sets the redirection up).

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.