所以,我/bin/bash不小心用一个愚蠢的 bash 脚本覆盖了。我之前的问题可以在下面找到。建议我创建一个新的来处理出现的问题。回顾一下,我能够使用 GUI 将我的默认终端更改为 dash,我可以在其中运行命令。现在,我正在尝试重新安装 bash,以便我可以将默认终端改回。如前所述,我正在运行apt-get --reinstall installbash,它应该重新安装它。但是,它返回一个错误:
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)
Run Code Online (Sandbox Code Playgroud)
此外,dpkg --configure bash说它在处理包时出错,并且 bash “处于非常糟糕的不一致状态;您应该在尝试配置之前重新安装它。”
我正在运行的发行版是 Kali 2.2 滚动版,我已经知道我会对这个发行版产生很多仇恨,因为如果有的话,覆盖 bash 是一个错误。
新帖子,由@Philippos 推荐。旧帖子的链接在这里
cam*_*amh 11
问题是 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-binarycontrol-tar.gzdata.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
Run Code Online (Sandbox Code Playgroud)
您可以data.tar.xz通过运行来查看文件的内容:
$ ar p /var/cache/apt/archives/bash_4.4-5_amd64.deb data.tar.xz | xzcat | tar tvf -
...
./bin/bash
...
Run Code Online (Sandbox Code Playgroud)
你可以从中提取/bin/bash:
$ cd /tmp
$ ar p /var/cache/apt/archives/bash_4.4-5_amd64.deb data.tar.xz | xzcat | tar xvf - ./bin/bash
Run Code Online (Sandbox Code Playgroud)
既然你从/tmp. 您现在将拥有文件/tmp/bin/bash. 您可以将其复制回/bin并再次覆盖 bash,但这次有一些不错的内容。
有dpkg的工具,你可以用它来操作.deb文件,但因为它们是简单的档案,我觉得更容易记住如何使用ar(1),并tar(1)相对于dpkg的特定选项。