Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does this command kill my shell?

Tags:

linux

bash

ubuntu

Update: This is a more general command that is more reproducible. ShellFish identified that there is a more general pattern:

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. 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.

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). Expecting some nonsense about syntax issues or commands not found, we instead watched our shell simply quit. 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. Strangely, the behavior is not present on another box I have running byobu even if I detach from the session. It also doesn't happen on Cygwin. Unfortunately I'm limited to testing with Ubuntu 14.10 otherwise.

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.

like image 690
Zach Thacker Avatar asked Jun 26 '15 13:06

Zach Thacker


People also ask

Why does Linux kill processes?

The Linux Kernel may also decide to terminate one or more processes when the system is running low on resources. A very common example of that is the out-of-memory (OOM) killer, which takes action when the system's physical memory is getting exhausted.

What does the kill command do?

Description. The kill command sends a signal (by default, the SIGTERM signal) to a running process. This default action normally stops processes. If you want to stop a process, specify the process ID (PID) in the ProcessID variable.


1 Answers

I could reproduce this issue in an Ubuntu VM but not on an OEL VM. Difference was, on Ubuntu the package command-not-found was installed, and it provides the python script /usr/lib/command-not-found. This script is responsible for exiting the shell.

In /etc/bash.bashrc, there is a function command-not-found_handle , which executes /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.

From my /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 } 

like image 75
Shubhangi Avatar answered Oct 11 '22 07:10

Shubhangi