Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
205 views
in Technique[技术] by (71.8m points)

linux - 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:

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.

question from:https://stackoverflow.com/questions/31074910/why-does-this-command-kill-my-shell

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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
" "$1"
          return 127
     fi
}


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...