bashinterprocess

The difference between redirection with and without exec


Anyone clarify what the definitive difference between:

 3<&0

and

 exec 3<&0

of bash or other akin shell? thanks before


Solution

  • The difference is that file descriptor 3 remains open after exec 3<&0. See:

    $ cat foo
    bar
    $
    $ 3<foo
    $ cat <&3
    bash: 3: Bad file descriptor
    $
    $ exec 3<foo
    $ cat <&3
    bar
    $