OpenWrt Forum Archive

Topic: What is the >&- redirect in scripts?

The content of this topic has been archived on 28 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Forgive my ignorance, but I'm trying to understand what the ">&-" redirect target is in many of the OpenWrt scripts.

Unfortunately, I'm finding that this is a rather difficult term to search for.  Even enclosing it in quotes doesn't seem to mean much to any of the search engines I tried.

A link to a page explaining this would be most appreciated.

One suggestion on the IRC channel was that it was for logging.  I'd guess this would go to syslog, then.  However, doing an

echo test >&-

didn't result in "test" showing up in the log.

Thanks!

>&-

Close stdout.

The official documentation for "bash" at Gnu.org says:

3.6.8 Moving File Descriptors
The redirection operator
   
[n]<&digit-

moves the file descriptor digit to file descriptor n, or the standard input (file descriptor 0) if n is not specified. digit is closed after being duplicated to n.

Similarly, the redirection operator
   
[n]>&digit-

moves the file descriptor digit to file descriptor n, or the standard output (file descriptor 1) if n is not specified.

That doesn't quite cover the minimal version you're seeing, with no "n" and no "digit," but it's what I found.

The discussion might have continued from here.