Bash – Process substitution from curl to bash as root

bashfile-descriptorsprocess-substitutionsudo

I'm trying to run a script from URL as root with this command:

sudo bash <(curl -s http://copy.com/gLVZIqUubzcS/popcorn)

But I'm getting this error:

bash: /dev/fd/63: Aucun fichier ou dossier de ce type

French for "not found". Any ideas what it might be?

P.S: I'm running Ubuntu 12.04

Best Answer

Don't use process substitution like that. In practice, it's pretty much just this anyway:

sudo sh <<CURL_SCRIPT
    $(curl -s http://copy.com/gLVZIqUubzcS/popcorn)
CURL_SCRIPT

Or:

curl -s http://copy.com/gLVZIqUubzcS/popcorn | sudo sh

Unless the script you're trying to run makes use of bashisms the above will work. If it does use bash-only syntax you should do:

curl -s http://copy.com/gLVZIqUubzcS/popcorn | sudo . /dev/stdin

Though the above doesn't seem to work, which I expect is due to sudo not liking the shell's built-in .dot.

So do this:

curl -s http://copy.com/gLVZIqUubzcS/popcorn | sudo ${0#-} /dev/stdin

You could also simply do:

sudo sh -c "$(curl -s http://copy.com/gLVZIqUubzcS/popcorn)"

You don't need to invoke the bash executable again when you can use the shell's built-ins instead.

Related Question