我制作了一个简单的 shell 脚本来对所有已安装的软件包进行排序并删除不需要的软件包:
#!/bin/sh
pkgs=`dpkg --get-selections | awk '{ print $1 }' | cut -f1 -d :`
echo "$pkgs" | while IFS='' read -r line || [ -n "$line" ]; do
apt purge "$line"
done
但是当 shell 解释器调用apt purge "$line"
apt 时,它会停止并显示“Abort”消息。由于缺少交互式输入:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
sysvinit-core
The following packages will be REMOVED:
acl* systemd* systemd-sysv*
The following NEW packages will be installed:
sysvinit-core
0 upgraded, 1 newly installed, 3 to remove and 0 not upgraded.
Need to get 132 kB of archives.
After this operation, 12.2 MB disk space will be freed.
Do you want to continue? [Y/n] Abort.
如何apt purge "$line"
在执行时将输入传递给启动时的子进程?
最简单的选择是摆脱stdin的重新映射(特别是在由于使用管道 - 启动子 shell 时发生
|
)。即,像这样: