重定向与不使用exec的差异

huangapple go评论106阅读模式
英文:

The difference between redirection with and without exec

问题

"3<&0" 与 "exec 3<&0" 在Bash或其他类似的shell中的确切区别是什么?谢谢。

英文:

Anyone clarify what the definitive difference between:

 3&lt;&amp;0

and

 exec 3&lt;&amp;0

of bash or other akin shell?
thanks before

答案1

得分: 5

The difference is that file descriptor 3 remains open after exec 3&lt;&amp;0. See:

$ cat foo
bar
$
$ 3&lt;foo
$ cat &lt;&amp;3
bash: 3: Bad file descriptor
$
$ exec 3&lt;foo
$ cat &lt;&amp;3
bar
$
英文:

The difference is that file descriptor 3 remains open after exec 3&lt;&amp;0. See:

$ cat foo
bar
$
$ 3&lt;foo
$ cat &lt;&amp;3
bash: 3: Bad file descriptor
$
$ exec 3&lt;foo
$ cat &lt;&amp;3
bar
$

huangapple
  • 本文由 发表于 2023年5月10日 12:28:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/76214899.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定