0>&-和0 <&-I / O重定向的区别

问题描述

在下面的示例中,0>&-的工作原理是在出现输入提示时ssh-keygen命令存在。 应该不是0<&-关闭stdin)吗? 0>&-0<&-似乎都以相同的方式工作(当ssh-keygen的输入/确认提示显示关闭时)-如何解释?

user@system:~/.ssh$ ls -al test123
ls: cannot access 'test123': No such file or directory
user@system:~/.ssh$ ssh-keygen -b 2048 -t rsa -f test123 -q -N "" 0>&-
user@system:~/.ssh$
user@system:~/.ssh$ ls -al test123
-rw------- 1 user user 1823 Sep 21 08:01 test123
user@system:~/.ssh$ ssh-keygen -b 2048 -t rsa -f test123 -q -N "" 0>&-
test123 already exists.
Overwrite (y/n)? user@system:~/.ssh$
user@system:~/.ssh$
user@system:~/.ssh$ ssh-keygen -b 2048 -t rsa -f test123 -q -N "" 0<&-
test123 already exists.
Overwrite (y/n)? user@system:~/.ssh$

documentation中有:

n<&-

    Close input file descriptor n.
0<&-,<&-

    Close stdin.
n>&-

    Close output file descriptor n.

解决方法

0>&-0<&-之间没有区别。

>&-<&-之间是有区别的。

区别是:

>&-默认为n = 1

<&-默认为n = 0

在此StackExchange post

上了解更多

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...