Reputation: 87
I am somewhat familiar with redirecting and know that /dev/null can be used for hiding output, for example with
some_command > /dev/null
but I encountered the usage
< /dev/null some_command
in this ArchWiki article and would like to understand what it does.
My first guess is that it is equivalent to
some_command < /dev/null
but if this guess is correct, what is the benefit of redirecting /dev/null
to a command?
Upvotes: 2
Views: 143
Reputation: 781068
Yes, they're equivalent. I/O redirection can be put anywhere on the command line.
When reading, /dev/null
returns EOF immediately. Redirecting input from /dev/null
is useful if you want to prevent the application from trying to read from whatever its initial standard input is, e.g. the terminal.
A common use of this is when running a program in the background via SSH and you want the SSH connection to close immediately. The connection won't close until all the file descriptors referring to it are closed, so you redirect all the standard descriptors:
ssh servername 'somecommand </dev/null >/dev/null 2>&1 &'
Upvotes: 5