Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm on Debian Lenny. Unfortunately, the factory sudo package is not including the -n option that ships with sudo version 1.7. I'd really like to have a way to specify "If sudo asks for a password, I prefer to fail immediately instead of hanging on a prompt". Will this alternative work?

echo "" | sudo -S -u lalala command 
share|improve this question

Your command will end up reading from standard input as well (as Chris Acheson). You'd better redirect standard input back from the terminal.

echo | sudo -S -u lalala sh -c 'command </dev/tty'
share|improve this answer

This will only work with certain commands. When it needs a password, sudo will fail as expected, in a somewhat ugly fashion. When it doesn't, however, the newline will be piped to the command that you're running with sudo.

cat works fine:

cacheson@segfault:~$ echo "" | sudo -S -u cacheson cat file.txt 
text file

vim does not:

cacheson@segfault:~$ echo "" | sudo -S -u cacheson vim file.txt 
Vim: Warning: Input is not from a terminal
Vim: Error reading input, exiting...

Vim: Finished.
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .