2 Answers
2

The easiest way I can think of, since the line in question is a command, is:

`$easy_install 2>&1 | grep sudo`

The backticks or $(…) take the output of a command pipe and execute it as if you typed it, returning the output.

Please note that this command won't work if you're missing sudo and trying to install it. But since this is obviously Ubuntu, sudo is usually available. To avoid this, you might want to try your second choice:

`$easy_install 2>&1 | tail -n 1`

Try and wean yourself out of using tail -1, it's being replaced by the standard form tail -n 1. I find this hard myself, but I don't like deprecation warnings. :)

Warning: if $easy_installexists and you don't get this type of output, either of these commands are a massive security risk. You can end up executing arbitrary things. You can protect yourself by being more extravagant:

`$easy_install 2>&1 >/dev/null | grep '^sudo apt-get install'`

This discards stdout, and will only run anything starting with sudo apt-get install which limits things nicely, but is considerably more annoying than just typing sudo apt-get install $package yourself.