输入未知命令时终端不执行任何操作

输入未知命令时终端不执行任何操作

当我输入系统上未知的命令时,asdf: command not found终端不会收到通常的错误消息,而是静静地待在那里什么也不做。如果我终止它,有时我什么也看不到,但有时我会看到一些 python 函数收到键盘中断,例如

$ asd
^CTraceback (most recent call last):
  File "/usr/lib/python2.7/encodings/__init__.py", line 31, in <module>

import codecs
  File "/usr/lib/python2.7/codecs.py", line 8, in <module>
    """#"
KeyboardInterrupt

或者

$ cpioquw
^CTraceback (most recent call last):
  File "/usr/lib/command-not-found", line 5, in <module>
    from __future__ import absolute_import, print_function
KeyboardInterrupt

或者

$ asdf
^CTraceback (most recent call last):
  File "/usr/lib/python2.7/site.py", line 563, in <module>

    main()
  File "/usr/lib/python2.7/site.py", line 546, in main
    known_paths = addsitepackages(known_paths)
  File "/usr/lib/python2.7/site.py", line 328, in addsitepackages
addsitedir(sitedir, known_paths)
  File "/usr/lib/python2.7/site.py", line 190, in addsitedir
    names = os.listdir(sitedir)
KeyboardInterrupt

消息似乎完全不一致,我以前从未见过这种情况。您知道问题可能出在哪里吗?或者我应该如何开始调查?

删除.bashrc似乎没有任何效果,在虚拟终端中尝试也没有任何效果。我创建了一个新用户,那里的行为符合预期。我猜问题出在我的某个bash配置文件中,但我不知道应该检查哪些文件。

我也尝试重新安装该command-not-found软件包,但也没有效果。

我现在已经尝试过了

sudo apt-get purge command-not-found command-not-found-data

它会抛出一个错误,这可能意味着一些事情:

$ sudo apt-get purge command-not-found command-not-found-data 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  bbswitch-dkms dkms lib32gcc1 libc6-i386 libcuda1-331 libvdpau1 nvidia-prime
  nvidia-settings python-gdbm screen-resolution-extra
Use 'apt-get autoremove' to remove them.
The following packages will be REMOVED
  command-not-found* command-not-found-data* python3-commandnotfound*
0 to upgrade, 0 to newly install, 3 to remove and 238 not to upgrade.
2 not fully installed or removed.
After this operation, 4,205 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 287818 files and directories currently installed.)
Removing command-not-found (0.3ubuntu12) ...
Purging configuration files for command-not-found (0.3ubuntu12) ...
Removing python3-commandnotfound (0.3ubuntu12) ...
  File "/usr/bin/py3clean", line 4
SyntaxError: Non-ASCII character '\xc2' in file /usr/bin/py3clean on line 4, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
dpkg: error processing package python3-commandnotfound (--purge):
 subprocess installed pre-removal script returned error exit status 1
  File "/usr/bin/py3compile", line 4
SyntaxError: Non-ASCII character '\xc2' in file /usr/bin/py3compile on line 4, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
dpkg: error while cleaning up:
 subprocess installed post-installation script returned error exit status 1
Removing command-not-found-data (0.3ubuntu12) ...
Errors were encountered while processing:
 python3-commandnotfound
E: Sub-process /usr/bin/dpkg returned an error code (1)

执行此操作后,我注意到如果我运行pythonpython3最终运行相同的版本 2.7.6。这可能与问题有关吗?

答案1

如果您输入declare -f -p,bash 将列出所有已定义的 shell 函数。如果有一个名为 的函数command_not_found_handle,则将调用该函数,而不是 shell 的常规行为(仅在 bash 4 中)。据推测,在您的情况下,该 shell 函数已挂起。

(在我的 Debian 系统上,该函数在 中定义/etc/bash.bashrc,由 运行/etc/profile,它是所有 Bournelike shell 的系统范围启动文件。它所做的就是调用命令command-not-found,也就是您看到回溯的 Python 脚本。)

相关内容