Page 1 of 1 [ 3 posts ] 

moo_cow
Sea Gull
Sea Gull

User avatar

Joined: 1 Nov 2007
Age: 40
Gender: Male
Posts: 201
Location: SA, Texas

23 Nov 2007, 4:53 pm

What does this do in bash?

command >&- 2>&-



twosheds
Raven
Raven

User avatar

Joined: 23 Feb 2007
Age: 44
Gender: Male
Posts: 108

23 Nov 2007, 5:53 pm

It runs command without a stdout or stderr, i.e. with file descriptors 1 and 2 closed.



lau
Veteran
Veteran

User avatar

Joined: 17 Jun 2006
Age: 76
Gender: Male
Posts: 9,795
Location: Somerset UK

23 Nov 2007, 7:01 pm

Ah well, one never stops learning. I don't think I've ever had the occasion to run something with stdout/stderr closed. Redirected to /dev/null, yes... closed, no.
You would need to be pretty confident that "command" was going to acheive completion of what you ask it to do, even should it barf on the i/o error it will be getting if it attempts to output anything.
I.e. where

Code:
command >/dev/null 2>&1
would always perform "command" to completion, discarding all output,
Code:
command >&- 2>&-
might fall over halfway through, because of a failed attempt to output to stdout.


_________________
"Striking up conversations with strangers is an autistic person's version of extreme sports." Kamran Nazeer