使用和不使用 exec 重定向之间的区别

0 bash interprocess

任何人都可以澄清以下之间的明确区别:

 3<&0
Run Code Online (Sandbox Code Playgroud)

 exec 3<&0
Run Code Online (Sandbox Code Playgroud)

bash 或其他类似的 shell?之前谢谢

ogu*_*ail 5

不同之处3在于文件描述符在exec 3<&0. 看:

$ cat foo
bar
$
$ 3<foo
$ cat <&3
bash: 3: Bad file descriptor
$
$ exec 3<foo
$ cat <&3
bar
$
Run Code Online (Sandbox Code Playgroud)