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] 删除。
我来说两句