How do file descriptors work?

前端 未结 4 1736
礼貌的吻别
礼貌的吻别 2020-11-29 16:46

Can someone tell me why this does not work? I\'m playing around with file descriptors, but feel a little lost.

#!/bin/bash
echo \"This\"
echo \"is\" >&         


        
4条回答
  •  天涯浪人
    2020-11-29 17:23

    File descriptors 0, 1 and 2 are for stdin, stdout and stderr respectively.

    File descriptors 3, 4, .. 9 are for additional files. In order to use them, you need to open them first. For example:

    exec 3<> /tmp/foo  #open fd 3.
    echo "test" >&3
    exec 3>&- #close fd 3.
    

    For more information take a look at Advanced Bash-Scripting Guide: Chapter 20. I/O Redirection.

提交回复
热议问题