简体   繁体   中英

What does this shell command mean “exec 3>&1 > >(logger -t ”OKOK“)”

I've found the following bash command in some source code.

exec 3>&1 > >(logger -t "OKOK")

What does it exactly mean?

As far as I know, it redirects those log to the syslog.

However, What is 3>&1 ?

I have never seen a file descriptor of 3 before.

unusual indeed, but it does exist:

Each open file gets assigned a file descriptor. The file descriptors for stdin, stdout, and stderr are 0, 1, and 2, respectively. For opening additional files, there remain descriptors 3 to 9 . It is sometimes useful to assign one of these additional file descriptors to stdin, stdout, or stderr as a temporary duplicate link. This simplifies restoration to normal after complex redirection and reshuffling

Find out more on the IO redirection page .

From this line on, everything printed to STDOUT will be processed by logger . The original STDOUT has been saved in fd3, so you can later (if needed) restore the normal STDOUT. See Advanced BASH Scripting Guide for details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM