所以,我/bin/bash
不小心用一个愚蠢的 bash 脚本覆盖了。我之前的问题可以在下面找到。建议我创建一个新的来处理出现的问题。回顾一下,我能够使用 GUI 将默认终端更改为 dash,我可以在其中运行命令。现在,我正在尝试重新安装 bash,以便可以将默认终端更改回来。如前所述,我正在运行apt-get --reinstall install
bash,这应该重新安装它。但是,它返回一个错误:
reading package lists...
Building dependency tree...
Reading state information...
The following additional packages will be installed:
bash-completion
Suggested packages:
bash-doc
The following packages will be upgraded:
bash bash-completion
2 upgraded, 0 newly installed, 0 to remove and 2128 not upgraded.
2 not fully installed or removed.
Need to get 0 B/1,605 kB of archives.
After this operation, 673 kB of additional disk space will be used.
Do you want to continue? [Y/n] (Reading database ...
(Reading database ... 5%
(Reading database ... 10%
(Reading database ... 15%
(Reading database ... 20%
(Reading database ... 25%
(Reading database ... 30%
(Reading database ... 35%
(Reading database ... 40%
(Reading database ... 45%
(Reading database ... 50%
(Reading database ... 55%
(Reading database ... 60%
(Reading database ... 65%
(Reading database ... 70%
(Reading database ... 75%
(Reading database ... 80%
(Reading database ... 85%
(Reading database ... 90%
(Reading database ... 95%
(Reading database ... 100%
(Reading database ... 307792 files and directories currently installed.)
Preparing to unpack .../archives/bash_4.4-5_amd64.deb ...
dpkg (subprocess): unable to execute old pre-removal script (/var/lib/dpkg/info/bash.prerm): No such file or directory
dpkg: warning: subprocess old pre-removal script returned error exit status 2
dpkg: trying script from the new package instead ...
dpkg (subprocess): unable to execute new pre-removal script (/var/lib/dpkg/tmp.ci/prerm): No such file or directory
dpkg: error processing archive /var/cache/apt/archives/bash_4.4-5_amd64.deb (--unpack):
subprocess new pre-removal script returned error exit status 2
dpkg (subprocess): unable to execute installed post-installation script (/var/lib/dpkg/info/bash.postinst): No such file or directory
dpkg: error while cleaning up:
subprocess installed post-installation script returned error exit status 2
Errors were encountered while processing:
/var/cache/apt/archives/bash_4.4-5_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
此外,还dpkg --configure bash
表示它在处理包时出错,并且 bash 处于“非常糟糕的不一致状态;您应该在尝试配置之前重新安装它”。
我正在运行的发行版是 Kali 2.2,我已经知道我会非常讨厌这个发行版,因为如果有的话,覆盖 bash 是一个错误。
新帖子,由 @Philippos 推荐。旧帖子的链接是这里
答案1
问题是 bash prerm 脚本使用 bash,因此它无法运行,导致整个重新安装失败。
有多种方法可以解决这个问题:
1) 我的系统(Debian不稳定和Debian稳定)上的bash prerm脚本非常简单,不需要bash来运行。因此,只需编辑/var/lib/dpkg/info/bash.prerm
并将第一行从 更改#! /bin/bash
为#! /bin/sh
。还要确保/bin/sh
没有指向bash
( ls -l /bin/sh
)。如果是,您可能已经/bin/dash
安装了,因此请尝试编辑 prerm 文件以使用它。
2)删除prerm文件并重新安装。 prerm 文件在 Debian 4.4-5 版本中没有任何重要作用,因此您可以删除 prerm 文件并尝试重新安装。
3) 您可以/bin/bash
从.deb
已下载的存档中解压。您可以在输出中看到路径:/var/cache/apt/archives/bash_4.4-5_amd64.deb
。这是一个ar(1)
包含三个文件的存档:
debian-binary
control-tar.gz
data.tar.xz
请注意,该data.tar
文件可能不是xz
压缩文件 - 还有其他格式 - gzip、bzip 等。我将假设它是一个xz
文件,但如果不是,您可以适当地替换该后缀和 zcat 程序。
.deb
您可以通过运行以下命令查看文件的内容:
$ ar t /var/cache/apt/archives/bash_4.4-5_amd64.deb
debian-binary
control.tar.gz
data.tar.xz
data.tar.xz
您可以通过运行以下命令查看文件的内容:
$ ar p /var/cache/apt/archives/bash_4.4-5_amd64.deb data.tar.xz | xzcat | tar tvf -
...
./bin/bash
...
您可以/bin/bash
从中提取:
$ cd /tmp
$ ar p /var/cache/apt/archives/bash_4.4-5_amd64.deb data.tar.xz | xzcat | tar xvf - ./bin/bash
既然你从/tmp
.您现在将拥有文件/tmp/bin/bash
.您可以将其复制回/bin
并再次覆盖 bash,但这次包含一些好的内容。
您可以使用 dpkg 工具来操作文件,但由于它们是简单的存档,因此我发现与dpkg 特定选项相比,.deb
更容易记住如何使用。ar(1)
tar(1)