为什么python在这里运行?

简体中文

Ubuntu 20.04。使用 bash。我打错字了。我可以简化为:

a </

基本上:从目录重定向的带有 stdin 的未知命令。

我希望结果是:

a: command not found

但是,使用 Ubuntu 20.04(不是 debian)和 bash(不是busybox、dash、ksh、tcsh),我得到:

Fatal Python error: init_sys_streams: <stdin> is a directory, cannot continue
Python runtime state: core initialized

Current thread 0x00007f83aacaa740 (most recent call first):
<no Python frame>

这是怎么回事?为什么涉及python?

钢刀

Bash 通过一个command_not_found_handle函数实现了这个功能:

$ declare -f -p command_not_found_handle
command_not_found_handle ()
{
    if [ -x /usr/lib/command-not-found ]; then
        /usr/lib/command-not-found -- "$1";
        return $?;
    else
        if [ -x /usr/share/command-not-found/command-not-found ]; then
            /usr/share/command-not-found/command-not-found -- "$1";
            return $?;
        else
            printf "%s: command not found\n" "$1" 1>&2;
            return 127;
        fi;
    fi
}

如您所见,该函数尝试调用/usr/lib/command-not-found- 这是一个 python 脚本:

$ file /usr/lib/command-not-found
/usr/lib/command-not-found: Python script, ASCII text executable

以函数名称(在本例中为a)作为参数。然而,shell 已经从/-重定向了标准输入,所以它有效地调用python3了输入重定向:

$ python3 </
Fatal Python error: init_sys_streams: <stdin> is a directory, cannot continue
Python runtime state: core initialized

Current thread 0x00007f16b0ab0740 (most recent call first):
<no Python frame>

如果使用set -x以下命令运行命令,您可以更清楚地看到序列

$ set -x
$ 
$ a </
+ a
+ '[' -x /usr/lib/command-not-found ']'
+ /usr/lib/command-not-found -- a
Fatal Python error: init_sys_streams: <stdin> is a directory, cannot continue
Python runtime state: core initialized

Current thread 0x00007feb94250740 (most recent call first):
<no Python frame>
+ return 1

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

为什么python在这里运行?

来自分类Dev

为什么在这里使用Python打印花括号?

来自分类Dev

(python)为什么.append()在这里不起作用?

来自分类Dev

为什么Python在这里打印出多个值?

来自分类Dev

为什么python在这里复制列表?

来自分类Dev

为什么在这里不确定?

来自分类Dev

为什么在这里的盒子?

来自分类Dev

为什么WlanOpenHandle()在这里失败?

来自分类Dev

为什么在这里发生僵局

来自分类Dev

为什么在这里使用锁?

来自分类Dev

为什么$ .isEmptyObject在这里无效

来自分类Dev

为什么使用原子在这里?

来自分类Dev

为什么在这里需要'break;'?

来自分类Dev

为什么WlanOpenHandle()在这里失败?

来自分类Dev

为什么在这里抛出异常?

来自分类Dev

为什么$ .isEmptyObject在这里无效

来自分类Dev

为什么在这里得到NullPointerException?

来自分类Dev

为什么不会 for ... 在这里循环?

来自分类Dev

Python:%s 在这里做什么?

来自分类Dev

为什么,虽然while循环在这里无限期地运行?

来自分类Dev

为什么在这里两次运行程序

来自分类Dev

为什么awk在这里什么也不做?

来自分类Dev

为什么在这里使用嵌套循环时python打印奇怪的结果?

来自分类Dev

为什么在这里需要shell = True才能使Python的subprocess.check_output工作?

来自分类Dev

为什么Python的unittest.assertRaises()不会在这里引发错误?

来自分类Dev

docker-compose:为什么在这里调用我的 python 应用程序?

来自分类Dev

为什么在这里进行收益优化

来自分类Dev

为什么我的部署检查在这里失败

来自分类Dev

为什么decltype(auto)在这里返回引用?

Related 相关文章

热门标签

归档