I have a misbehaving program that I need to call from my script. It exits as soon as it sees something on stdin. Is there a way to close stdin?


Is there a way to close stdin?

Closing File Descriptors

  • n<&- Close input file descriptor n.

  • 0<&- or <&- Close stdin.

Source Chapter 20. I/O Redirection


Just pipe in a program with no output:

: | misbehaving_program
  • Wow, what is this? What does ':' do? – KaiserKatze May 24 at 5:47
  • ":" is an internal command of the shell that does nothing. It lets you introduce comments, or can be used for redirections. For example ": > file" creates an empty file. Or ": |" in this case feeds an empty stream to the command. – Raúl Salinas-Monteagudo May 24 at 7:16

Found it, you can close stdin with:

exec 0<&-

According to what you say, you might fix your problem by simply

pickyProgram < /dev/null

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.