我通过macOS终端连接到远程Debian系统。
apt-get
安装了某些内容,则apt-get
之后的命令将永远不会运行首先,我从macOS上的文本文件复制这三个命令,然后按一次命令 + v 将其粘贴到终端中:
sudo apt-get -y remove tree
sudo apt-get -y install tree
echo hi
这是我在终端机中看到的内容。
lone@lone:~$ sudo apt-get -y remove tree
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package 'tree' is not installed, so not removed
0 upgraded, 0 newly installed, 0 to remove and 17 not upgraded.
lone@lone:~$ sudo apt-get -y install tree
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
tree
0 upgraded, 1 newly installed, 0 to remove and 17 not upgraded.
Need to get 0 B/46.1 kB of archives.
After this operation, 106 kB of additional disk space will be used.
Selecting previously unselected package tree.
(Reading database ... 31853 files and directories currently installed.)
Preparing to unpack .../tree_1.7.0-5_amd64.deb ...
Unpacking tree (1.7.0-5) ...
Setting up tree (1.7.0-5) ...
Processing triggers for man-db (2.7.6.1-2) ...
lone@lone:~$
第三个命令echo hi
从未执行过。为什么?
apt-get
没有安装任何东西,则apt-get
之后的命令会运行下一次,我只需按一次命令 + v 粘贴以下两个命令即可:
sudo apt-get -y install tree
echo hi
这次,由于已经安装了tree
,因此apt-get
不需要再次安装。这是我看到的输出:
lone@lone:~$ sudo apt-get -y install tree
Reading package lists... Done
Building dependency tree
Reading state information... Done
tree is already the newest version (1.7.0-5).
0 upgraded, 0 newly installed, 0 to remove and 17 not upgraded.
lone@lone:~$ echo hi
hi
这次执行echo hi
。为什么?
每次执行这两套操作时,两个结果都是可重复的。为什么echo hi
命令在第一个示例中不运行,而在第二个示例中运行?
答案 0 :(得分:1)
apt-get
或由apt-get
调用的程序正在清空其stdin(恰好与您的命令列表所在的shell相同)。
由于您不知道需要从用户那里读取任何内容,因此可以从/ dev / null重定向stdin:
sudo apt-get -y remove tree </dev/null
sudo apt-get -y install tree </dev/null
echo hi