简体   繁体   English

为什么这个命令会杀死我的shell?

[英]Why does this command kill my shell?

Update: This is a more general command that is more reproducible. 更新:这是一个更通用的命令,更具可重现性。 ShellFish identified that there is a more general pattern: ShellFish发现存在更普遍的模式:

non-existingcommand & existingcommand &

for example, 例如,

xyz & echo &

Also, I had a coworker try over an ssh connection and his connection was closed after running the command. 此外,我有一个同事尝试ssh连接,并在运行命令后关闭了他的连接。 So this doesn't appear to be limited to a certain terminal emulator. 所以这似乎并不局限于某个终端仿真器。

Original question : 原始问题

echo?a=1&b=2|3&c=4=

Behavior: 行为:

After executing the command, my current Gnome Terminal tab closes without warning. 执行命令后,我当前的Gnome终端选项卡会在没有警告的情况下关闭。

Background: 背景:

We were testing a URL with a curl command but forgot to quote it or escape the special characters (hence the ampersands and equals signs). 我们用curl命令测试了一个URL,但忘了引用它或者转义特殊字符(因此是&符号和等号)。 Expecting some nonsense about syntax issues or commands not found, we instead watched our shell simply quit. 期待一些关于语法问题或未找到的命令的废话,我们反而只看到我们的shell退出了。 We spent some time narrowing the command down to the minimum that would cause the behavior. 我们花了一些时间将命令缩小到导致行为的最小值。

We are using Gnome Terminal on Ubuntu 14.10. 我们在Ubuntu 14.10上使用Gnome Terminal。 Strangely, the behavior is not present on another box I have running byobu even if I detach from the session. 奇怪的是,即使我从会话中分离出来,我在运行byobu的另一个盒子上也没有这种行为。 It also doesn't happen on Cygwin. 它也不会发生在Cygwin上。 Unfortunately I'm limited to testing with Ubuntu 14.10 otherwise. 不幸的是,我仅限于使用Ubuntu 14.10进行测试。

Note: The following command also kills my terminal but only about half of the time : 注意:以下命令也会终止我的终端,但只有大约一半的时间

echo?a=1&b=2&c=3=

Additional tests: 附加测试:

Someone recommend using a subshell... 有人推荐使用子壳...

guest-cvow8T@chortles:~$ bash -c 'echo?a=1&b=2|4&c=3='
bash: echo?a=1: command not found
guest-cvow8T@chortles:~$ bash: 4: command not found

No exit. 没有出口。

I could reproduce this issue in an Ubuntu VM but not on an OEL VM. 我可以在Ubuntu VM中重现此问题,但不能在OEL VM上重现此问题。 Difference was, on Ubuntu the package command-not-found was installed, and it provides the python script /usr/lib/command-not-found . 区别在于,在Ubuntu上安装了package command-not-found ,它提供了python脚本/usr/lib/command-not-found This script is responsible for exiting the shell. 该脚本负责退出shell。

In /etc/bash.bashrc , there is a function command-not-found_handle , which executes /usr/lib/command-not-found . /etc/bash.bashrc ,有一个函数command-not-found_handle ,它执行/usr/lib/command-not-found Hence, the terminal exits when we try to execute such commands. 因此,当我们尝试执行这样的命令时终端退出。 When I commented out the call to /usr/lib/command-not-found , the issue was no longer reproducible. 当我注释掉对/usr/lib/command-not-found的调用时,问题不再可重现。

From my /etc/bash.bashrc : 从我的/etc/bash.bashrc

function command_not_found_handle {
     #check because c-n-f could've been removed in meantime 
     if [ -x /usr/lib/command-not-found ]; then 
          /usr/bin/python /usr/lib/command-not-found -- "$1"
          return $?
     elif [ -x /usr/share/command-not-founf/command-not-found ]; then
          /usr/bin/python /usr/share/command-not-founf/command-not-found -- "$1"
          return $?
     else
          printf "%s:command not found\n" "$1"
          return 127
     fi
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM