Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

2 Answers

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
add comment

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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.